| Server IP : 38.190.208.107 / Your IP : 216.73.217.13 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/wp.2/wp-content/themes/blocksy/static/js/backend/ |
Upload File : |
import { __ } from 'ct-i18n'
import {
useRef,
useState,
Fragment,
createElement,
createPortal,
useEffect,
createRoot,
} from '@wordpress/element'
import $ from 'jquery'
import OptionsPanel from '../options/OptionsPanel'
import { getValueFromInput } from '../options/helpers/get-value-from-input'
const TaxonomyRoot = ({ options, input_name, value, tbody, purpose }) => {
const [internalValue, setInternalValue] = useState(value)
const input = useRef()
useEffect(() => {
const cb = (_, __, { data }) => {
if (data) {
const urlParams = new URLSearchParams(data)
if (urlParams.get('action') === 'add-tag') {
setInternalValue(value)
}
}
}
$(document).on('ajaxComplete', cb)
return () => {
$(document).off('ajaxComplete', cb)
}
}, [])
return (
<Fragment>
<input
value={JSON.stringify(
Array.isArray(internalValue) ? {} : internalValue
)}
onChange={() => {}}
name={input_name}
type="hidden"
ref={input}
/>
{createPortal(
<OptionsPanel
value={internalValue}
options={options}
onChange={(key, newValue) => {
setInternalValue((internalValue) => ({
...internalValue,
[key]: newValue,
}))
$(input.current).change()
}}
purpose={purpose}
/>,
tbody
)}
</Fragment>
)
}
export const initTaxonomies = () => {
const maybeTaxonomyField = document.querySelector(
'[name*="blocksy_taxonomy_meta_options"]'
)
if (!maybeTaxonomyField) {
return
}
if (!maybeTaxonomyField.dataset.options) {
return
}
let options = JSON.parse(maybeTaxonomyField.dataset.options)
const maybeTable = document.querySelector('.form-table')
let tbody = null
let purpose = 'taxonomy'
if (!maybeTable) {
const rootEl = document.querySelector('#addtag')
tbody = document.createElement('div')
tbody.classList.add('form-field', 'ct-term-screen-create')
tbody.textContent = ''
rootEl.insertBefore(tbody, rootEl.querySelector('.submit'))
purpose = 'default'
} else {
tbody = maybeTable.querySelector('tbody')
}
const root = createRoot(maybeTaxonomyField.parentNode)
root.render(
<TaxonomyRoot
input_name={maybeTaxonomyField.name}
options={options}
tbody={tbody}
value={getValueFromInput(
options,
JSON.parse(maybeTaxonomyField.value),
null,
false
)}
purpose={purpose}
/>
)
}