HEX
Server: Apache
System: Linux server11 5.10.0-33-amd64 #1 SMP Debian 5.10.226-1 (2024-10-03) x86_64
User: web78 (5081)
PHP: 7.4.33
Disabled: 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_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/clients/client1/web78/web/wp-content/plugins/widget-logic/block/js/widget-logic.js
const { createHigherOrderComponent: createHOC } = wp.compose;
const { Fragment } = wp.element;
const { InspectorAdvancedControls } = wp.blockEditor;
const { TextareaControl } = wp.components;
const { addFilter } = wp.hooks;
const { __ } = wp.i18n;

const _extends = Object.assign || function (target) {
    for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i];for (var key in source) {
            if (Object.prototype.hasOwnProperty.call(source, key)) {
                target[key] = source[key];
            }
        }
    }
    return target;
};


// Blocks that are not compatible at all with widget logic.
const globallyIncompatible = ['core/freeform', 'core/legacy-widget', 'core/widget-area'];

/**
 * Add logic to block.
 *
 * @param {object} cfg Current block config.
 *
 * @returns {object} Modified block settings.
 */
const addWidgetLogicControlAttribute = cfg => {
    // The freeform (Classic Editor) blocks are not compatible because it does not
    // support custom attributes and can be config with prev version of widget logic.
    if (globallyIncompatible.includes(cfg.name)) {
        return cfg;
    }

    if ('undefined' !== typeof cfg.attributes) {
        const attributes = {
            widgetLogic: {
                type: 'string',
                default: '',
            },
        }

        // Use Lodash's assign to gracefully handle if attributes are undefined
        cfg.attributes = _extends(cfg.attributes ?? {}, attributes);
        cfg.supports = _extends(cfg.supports ?? {}, {
            widgetLogic: true,
        });
    }

    return cfg;
};

addFilter('blocks.registerBlockType', 'widgetLogic/attribute', addWidgetLogicControlAttribute);

/**
 * Create Higher order component to add React layout control to inspector controls of block.
 */
const withLogicField = createHOC(BlockEdit => {
    return props => {
        const { attributes, setAttributes, isSelected } = props;
        const { widgetLogic } = attributes;

        return React.createElement(
            Fragment,
            null,
            React.createElement(BlockEdit, props),
            isSelected && !globallyIncompatible.includes(props.name) && React.createElement(
                InspectorAdvancedControls,
                null,
                React.createElement(TextareaControl, {
                    rows: '2',
                    label: __('Widget Logic', 'widget-logic'),
                    help: __('Add PHP condition that returns true or false or valid PHP conditional tags.', 'widget-logic'),
                    value: widgetLogic ? widgetLogic : '',
                    onChange: newValue => setAttributes({
                        widgetLogic: newValue
                    })
                })
            )
        );
    };
}, 'withLogicField');



addFilter('editor.BlockEdit', 'widgetLogic/controlField', withLogicField);

/**
 * add a data attribute to the block wrapper "editor-block-list__block"
 * this hook only fires for the BE/Admin View
 */

const addWrapperField = createHOC(BlockListBlock => {
        return props => {
                const { widgetLogic } = props.attributes;

                const { name } = props.block;

                let newName = name.replace(/\w+\//gm, '');
                newName = newName.charAt(0).toUpperCase() + newName.slice(1);

                let wrapperProps = props.wrapperProps;
                let customData = {};

                if ('undefined' !== typeof widgetLogic && widgetLogic) {
                        customData = _extends(customData, {
                                'data-cfg-widget-logic': __('Widget Logic:', 'widget-logic') + ' ' + widgetLogic
                        });
                }

                wrapperProps = _extends(wrapperProps ?? {}, customData);

                return React.createElement(BlockListBlock, _extends({}, props, { wrapperProps: wrapperProps }));
        };
}, 'addWrapperField');



addFilter('editor.BlockListBlock', 'widgetLogic/addWrapperField', addWrapperField);