Файловый менеджер - Редактировать - /var/www/xthruster/html/wp-content/uploads/flags/custom-code.tar
Назад
custom-code-metabox.php 0000644 00000027353 14721652711 0011154 0 ustar 00 <?php namespace ElementorPro\Modules\CustomCode; use Elementor\Utils; use ElementorPro\Modules\AssetsManager\Classes\Assets_Base; use ElementorPro\Plugin; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Custom_Code_Metabox extends Assets_Base { const FIELD_LOCATION = 'location'; const FIELD_PRIORITY = 'priority'; const FILED_EXTRA_OPTIONS = 'extra_options'; const FIELD_CODE = 'code'; const OPTION_LOCATION_HEAD = 'elementor_head'; const OPTION_LOCATION_BODY_START = 'elementor_body_start'; const OPTION_LOCATION_BODY_END = 'elementor_body_end'; const OPTION_PRIORITY_LENGTH = 10; const INPUT_OPTION_ENSURE_JQUERY = 'ensure_jquery'; const INPUT_FIELDS = [ self::FIELD_LOCATION, self::FIELD_PRIORITY, self::FIELD_CODE, self::FILED_EXTRA_OPTIONS, ]; const INPUT_OPTIONS = [ self::INPUT_OPTION_ENSURE_JQUERY, ]; public function get_name() { return Module::MODULE_NAME; } public function get_type() { return Module::CPT; } public function get_field_label( $field ) { $label = parent::get_field_label( $field ); if ( ! empty( $field['info'] ) ) { $label = '<p class="elementor-field-label"><i data-info="' . $field['info'] . '" class="eicon-info-circle"></i>' . $label . '</p>'; } return $label; } public function get_location_labels() { return [ self::OPTION_LOCATION_HEAD => esc_html__( 'Head', 'elementor-pro' ), self::OPTION_LOCATION_BODY_START => esc_html__( 'Body Start', 'elementor-pro' ), self::OPTION_LOCATION_BODY_END => esc_html__( 'Body End', 'elementor-pro' ), ]; } public function get_location_options() { return [ self::OPTION_LOCATION_HEAD => '<head>', self::OPTION_LOCATION_BODY_START => sprintf( /* translators: %s: Body opening tag. */ esc_html__( '%s - Start', 'elementor-pro' ), '<body>' ), self::OPTION_LOCATION_BODY_END => sprintf( /* translators: %s: Body closing tag. */ esc_html__( '%s - End', 'elementor-pro' ), '</body>' ), ]; } public function get_priority_options() { $start = 1; $result = range( $start, self::OPTION_PRIORITY_LENGTH ); $result = array_combine( $result, $result ); return $result; } /** * Add script integrity. * * This is method is public, since its has to remove its own filter. * * @param string $html * @param mixed $handle * * @return string */ public function add_script_integrity( $html, $handle ) { if ( 'jshint' === $handle ) { $html = str_replace( '></script>', ' integrity="sha512-qcoitUjhkmNyPmbIOlUV/zd8MJvrVcKrNqnveMWS3C6MYOl5+HLwliRKUm/Ae/dfIok6+E54hjgVrAeS+sBAGA==" crossorigin="anonymous"></script>', $html ); remove_filter( 'script_loader_tag', [ $this, 'add_script_integrity' ] ); } return $html; } protected function actions() { add_action( 'add_meta_boxes_' . Module::CPT, function () { $this->add_meta_boxes(); } ); add_action( 'save_post_' . Module::CPT, function( $post_id, $post, $update ) { return $this->save_post_meta( $post_id, $post ); }, 10, 3 ); add_action('post_submitbox_misc_actions', function ( $post ) { $this->add_meta_publish_options( $post ); } ); } private function get_fields() { return [ [ 'id' => 'open-div-meta-box', 'field_type' => 'html_tag', 'label' => false, 'tag' => 'div', 'attributes' => [ 'class' => 'elementor-custom-code-meta-box', ], ], [ 'id' => 'open-div-panel', 'field_type' => 'html_tag', 'label' => false, 'tag' => 'div', 'attributes' => [ 'class' => 'elementor-custom-code-panel', ], ], [ 'id' => 'open-div-placement', 'field_type' => 'html_tag', 'label' => false, 'tag' => 'div', 'attributes' => [ 'class' => 'elementor-custom-code-panel-placement', ], ], [ 'id' => self::FIELD_LOCATION, 'field_type' => 'select', 'label' => esc_html__( 'Location', 'elementor-pro' ) . ':', 'options' => $this->get_location_options(), 'info' => esc_html__( 'Define where the Custom Code will appear', 'elementor-pro' ), ], [ 'id' => 'open-div-placement', 'field_type' => 'html_tag', 'label' => false, 'tag' => 'div', 'attributes' => [ 'class' => 'elementor-custom-code-options-placement', ], ], [ 'id' => self::FILED_EXTRA_OPTIONS, 'field_type' => 'checkbox', 'options' => [ self::INPUT_OPTION_ENSURE_JQUERY => esc_html__( 'Always load jQuery', 'elementor-pro' ), ], 'info' => esc_html__( 'If your snippet includes jQuery, this will ensure it will work for all visitors. It may have a minor impact on loading speed.', 'elementor-pro' ), ], [ 'id' => 'close-div-placement', 'field_type' => 'html_tag', 'label' => false, 'tag' => 'div', 'close' => true, ], [ 'id' => self::FIELD_PRIORITY, 'field_type' => 'select', 'label' => esc_html__( 'Priority', 'elementor-pro' ) . ':', 'options' => $this->get_priority_options(), 'info' => esc_html__( 'Define in which order the Custom Code will appear', 'elementor-pro' ), ], [ 'id' => 'close-div-placement', 'field_type' => 'html_tag', 'label' => false, 'tag' => 'div', 'close' => true, ], [ 'id' => 'close-div-panel', 'field_type' => 'html_tag', 'label' => false, 'tag' => 'div', 'close' => true, ], [ 'id' => 'close-div-meta-box', 'field_type' => 'html_tag', 'label' => false, 'tag' => 'div', 'close' => true, ], [ 'id' => 'open-div-code-mirror-holder', 'field_type' => 'html_tag', 'label' => false, 'tag' => 'div', 'attributes' => [ 'class' => 'elementor-custom-code-codemirror-holder', ], ], [ 'id' => 'open-div-code-mirror', 'field_type' => 'html_tag', 'label' => false, 'tag' => 'div', 'attributes' => [ 'class' => 'elementor-custom-code-codemirror', ], ], [ 'id' => self::FIELD_CODE, 'field_type' => 'textarea', 'label' => '', 'extra_attributes' => [ 'class' => 'hidden', ], ], [ 'id' => 'close-div-code-mirror', 'field_type' => 'html_tag', 'label' => false, 'tag' => 'div', 'close' => true, ], [ 'id' => 'close-div-code-mirror-holder', 'field_type' => 'html_tag', 'label' => false, 'tag' => 'div', 'close' => true, ], ]; } private function get_code_editor_settings() { // TODO: Handle `enqueue_code_editor_scripts` to work with `lint => 'true'`. return [ 'type' => 'text/html', 'codemirror' => [ 'indentUnit' => 2, 'tabSize' => 2, 'gutters' => [ 'CodeMirror-lint-markers' ], ], ]; } private function enqueue_code_editor_scripts( $field_code_id ) { // Add integrity attribute to jshint. add_filter( 'script_loader_tag', [ $this, 'add_script_integrity' ], 10, 2 ); wp_enqueue_script( 'htmlhint' ); wp_enqueue_script( 'csslint' ); wp_deregister_script( 'jshint' ); wp_enqueue_script( 'jshint', 'https://cdnjs.cloudflare.com/ajax/libs/jshint/2.12.0/jshint.min.js', [], '2.12.0' ); /** * Some of the plugins may load 'code-editor' for their needs and change the default behavior, so it should * re-initialize the code editor with 'custom code' settings. */ if ( wp_script_is( 'code-editor' ) ) { wp_add_inline_script( 'custom-code-metabox', sprintf( 'wp.codeEditor.initialize( jQuery( "#%s"), %s );', $field_code_id, wp_json_encode( wp_get_code_editor_settings( $this->get_code_editor_settings() ) ) ) ); } else { wp_enqueue_code_editor( $this->get_code_editor_settings() ); wp_add_inline_script( 'code-editor', sprintf( 'wp.codeEditor.initialize( jQuery( "#%s") );', $field_code_id ) ); } } private function render_meta_box() { $fields = $this->get_fields(); if ( ! empty( $_REQUEST['action'] ) && 'edit' == $_REQUEST['action'] ) { $post = get_post( \ElementorPro\Core\Utils::_unstable_get_super_global_value( $_REQUEST, 'post' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not required here. foreach ( self::INPUT_FIELDS as $input_field ) { $field_meta = get_post_meta( $post->ID, "_elementor_$input_field", true ); if ( ! empty( $field_meta ) ) { $key = array_search( $input_field, array_column( $fields, 'id' ) ); if ( false !== $key ) { $fields[ $key ]['saved'] = $field_meta; } } } } // The method, support fields only. $this->print_metabox( $fields ); /** * Elementor metabox render. * * Fires before custom scripts are enqueued, since enqueue depends on * render handlers. * * @param Custom_Code_Metabox $this An instance of custom code metabox. * @param int|false $id The ID of the current WordPress post. * False if post is not set. */ do_action( 'elementor-pro/metabox/render', $this, get_the_ID() ); // Init codemirror. $this->enqueue_code_editor_scripts( self::FIELD_CODE ); } private function save_post_meta( $post_id, $post ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $post_id; } // Check the user's permissions. if ( ! current_user_can( 'edit_post', $post_id ) ) { return $post_id; } if ( get_post_status( $post->ID ) === 'auto-draft' ) { return $post_id; } // PHPCS - Should not validate for nonce (already done in WordPress save_post). $post_data = $_POST; // phpcs:ignore WordPress.Security.NonceVerification.Missing foreach ( self::INPUT_FIELDS as $field ) { if ( isset( $post_data[ $field ] ) && ! Utils::is_empty( $post_data[ $field ] ) ) { if ( self::FIELD_CODE === $field ) { $post_meta = $post_data[ $field ]; } else { $post_meta = sanitize_text_field( $post_data[ $field ] ); } if ( ! current_user_can( 'unfiltered_html' ) ) { $post_meta = wp_kses_post( $post_meta ); } update_post_meta( $post->ID, "_elementor_$field", $post_meta ); /** @var \ElementorPro\Modules\ThemeBuilder\Module $theme_builder */ $theme_builder = Plugin::instance()->modules_manager->get_modules( 'theme-builder' ); $theme_builder->get_conditions_manager()->get_cache()->regenerate(); } elseif ( self::FILED_EXTRA_OPTIONS === $field ) { $input_options = []; foreach ( self::INPUT_OPTIONS as $input_option ) { $key = self::FILED_EXTRA_OPTIONS . '_' . $input_option; $input_option_value = \ElementorPro\Core\Utils::_unstable_get_super_global_value( $post_data, $key ); if ( 'on' === $input_option_value ) { $input_options [] = $input_option; } } update_post_meta( $post->ID, "_elementor_$field", $input_options ); } } // Temporary workaround for applying conditions for draft custom code post. if ( ! empty( $post_data['_conditions'] ) ) { $conditions = (array) json_decode( wp_unslash( $post_data['_conditions'] ) ); foreach ( $conditions as $key => $item ) { $item_assoc_array = (array) $item; $conditions[ $key ] = [ $item_assoc_array['type'], $item_assoc_array['name'], $item_assoc_array['sub'], $item_assoc_array['subId'], ]; } /** @var \ElementorPro\Modules\ThemeBuilder\Module $theme_builder */ $theme_builder = Plugin::instance()->modules_manager->get_modules( 'theme-builder' ); $theme_builder->get_conditions_manager()->save_conditions( $post_id, $conditions ); } } private function add_meta_boxes() { add_meta_box( 'elementor-custom-code', __( 'Custom code', 'elementor-pro' ), function() { $this->render_meta_box(); }, module::CPT, 'normal', 'default' ); } private function add_meta_publish_options( $post ) { if ( Module::CPT === $post->post_type ) { ?> <div class="misc-pub-section misc-pub-post-conditions"> <i class="dashicons dashicons-networking" aria-hidden="true"></i> <?php echo esc_html__( 'Conditions:', 'elementor-pro' ); ?> <span class="post-conditions"></span> </div> <?php } } } module.php 0000644 00000034116 14721652711 0006555 0 ustar 00 <?php namespace ElementorPro\Modules\CustomCode; use Elementor\Core\Admin\Menu\Admin_Menu_Manager; use Elementor\Core\Documents_Manager; use Elementor\Icons_Manager; use Elementor\Settings; use Elementor\TemplateLibrary\Source_Local; use Elementor\Utils; use ElementorPro\Base\Module_Base; use ElementorPro\License\API; use ElementorPro\Modules\CustomCode\AdminMenuItems\Custom_Code_Menu_Item; use ElementorPro\Modules\CustomCode\AdminMenuItems\Custom_Code_Promotion_Menu_Item; use ElementorPro\Modules\ThemeBuilder\Classes\Conditions_Manager; use ElementorPro\Modules\ThemeBuilder\Classes\Locations_Manager; use ElementorPro\Plugin; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Module extends Module_Base { const CAPABILITY = 'manage_options'; const CPT = 'elementor_snippet'; const MODULE_NAME = 'custom_code'; const DOCUMENT_TYPE = 'code_snippet'; const ADDITIONAL_COLUMN_INSTANCES = 'instances'; const MENU_SLUG = 'edit.php?post_type=' . self::CPT; const PROMOTION_MENU_SLUG = 'e-custom-code'; /** * @var \ElementorPro\Modules\CustomCode\Custom_Code_Metabox */ public $meta_box; public function __construct() { parent::__construct(); $this->meta_box = new Custom_Code_Metabox(); $this->actions(); if ( $this->can_use_custom_code() ) { $this->register_custom_post_type(); $this->register_metabox(); } } public function get_name() { return 'custom-code'; } private function actions() { if ( $this->can_use_custom_code() ) { add_action( 'elementor/documents/register', function ( $documents_manager ) { return $this->register_documents( $documents_manager ); } ); add_action( 'elementor/theme/register_locations', function ( $location_manager ) { return $this->register_location( $location_manager ); } ); } add_action( 'elementor/admin/menu/register', function ( Admin_Menu_Manager $admin_menu_manager ) { $this->add_admin_menu( $admin_menu_manager ); } ); // TODO: BC - Remove after `Admin_Menu_Manager` will be the standard. add_action( 'admin_menu', function () { if ( did_action( 'elementor/admin/menu/register' ) ) { return; } $menu_title = esc_html__( 'Custom Code', 'elementor-pro' ); add_submenu_page( Settings::PAGE_ID, $menu_title, $menu_title, self::CAPABILITY, static::MENU_SLUG ); }, /* After custom icons */ 51 ); add_action( 'current_screen', function () { if ( ! is_admin() ) { return; } $current_screen = get_current_screen(); if ( 'edit-' . self::CPT === $current_screen->id ) { $this->admin_ui_actions(); } elseif ( self::CPT === $current_screen->id ) { // Enqueue assets. add_action( 'admin_enqueue_scripts', function () { $this->enqueue_assets(); }, 0 /* elementor-app-base styles should be loaded in early stages */ ); } } ); $this->frontend_actions(); } private function admin_ui_actions() { // Show blank 'custom code' snippets list. add_action( 'manage_posts_extra_tablenav', function ( $which ) { return $this->maybe_render_blank_state( $which ); } ); // Mange post columns. add_filter( 'manage_posts_columns', function ( $columns ) { return $this->manage_posts_columns( $columns ); } ); add_action( 'manage_posts_custom_column', function ( $column_name, $post_id ) { return $this->manage_posts_custom_column( $column_name, $post_id ); }, 10, 2 ); } private function frontend_actions() { // Print snippets. add_action( 'wp_head', function () { $this->print_snippets( Custom_Code_Metabox::OPTION_LOCATION_HEAD ); } ); add_action( 'wp_body_open', function () { $this->print_snippets( Custom_Code_Metabox::OPTION_LOCATION_BODY_START ); } ); add_action( 'wp_footer', function () { $this->print_snippets( Custom_Code_Metabox::OPTION_LOCATION_BODY_END ); }, 21 /* After 'wp_print_footer_scripts' */ ); } private function register_custom_post_type() { $labels = [ 'name' => esc_html__( 'Custom Code', 'elementor-pro' ), 'singular_name' => esc_html__( 'Custom Code', 'elementor-pro' ), 'add_new' => esc_html__( 'Add new', 'elementor-pro' ), 'add_new_item' => esc_html__( 'New code', 'elementor-pro' ), 'edit_item' => esc_html__( 'Edit code', 'elementor-pro' ), ]; register_post_type( self::CPT, [ 'labels' => $labels, 'public' => false, 'rewrite' => false, 'show_ui' => true, 'show_in_menu' => false, 'show_in_nav_menus' => false, 'exclude_from_search' => true, 'capability_type' => 'post', 'hierarchical' => false, 'supports' => [ 'title', 'author' ], 'capabilities' => [ 'publish_posts' => 'manage_options', 'edit_posts' => 'manage_options', 'edit_others_posts' => 'manage_options', 'delete_posts' => 'manage_options', 'delete_others_posts' => 'manage_options', 'read_private_posts' => 'manage_options', 'edit_post' => 'manage_options', 'delete_post' => 'manage_options', 'read_post' => 'manage_options', ], ] ); // Handling custom post type messages. add_filter( 'post_updated_messages', function( $messages ) { if ( self::CPT === get_post_type() ) { $post = get_post(); // Thanks 'WooCommerce' for the example. $messages[ self::CPT ] = [ '', // Not in use. __( 'Custom code updated.', 'elementor-pro' ), __( 'Custom field updated.', 'elementor-pro' ), __( 'Custom field deleted.', 'elementor-pro' ), __( 'Custom code updated.', 'elementor-pro' ), __( 'Revision restored.', 'elementor-pro' ), __( 'Custom code published.', 'elementor-pro' ), __( 'Custom code saved.', 'elementor-pro' ), __( 'Custom code submitted.', 'elementor-pro' ), sprintf( /* translators: %s: The scheduled date. */ __( 'Custom code scheduled for %s.', 'elementor-pro' ), '<strong>' . date_i18n( esc_html__( 'M j, Y @ G:i', 'elementor-pro' ), strtotime( $post->post_date ) ) . '</strong>' ), __( 'Custom code draft updated.', 'elementor-pro' ), ]; } return $messages; } ); add_filter( 'bulk_post_updated_messages', function ( $messages, $counters ) { $current_screen = get_current_screen(); if ( $current_screen && self::CPT === $current_screen->post_type ) { $messages[ self::CPT ] = [ 'updated' => _n( '%s custom code updated.', '%s custom codes updated.', $counters['updated'], 'elementor-pro' ), 'locked' => _n( '%s custom code cannot be not updated, someone else is editing it.', '%s custom codes cannot be not updated, someone else is editing them.', $counters['locked'], 'elementor-pro' ), 'deleted' => _n( '%s custom code permanently deleted.', '%s custom codes permanently deleted.', $counters['deleted'], 'elementor-pro' ), 'trashed' => _n( '%s custom code moved to trash.', '%s custom codes moved to trash.', $counters['trashed'], 'elementor-pro' ), 'untrashed' => _n( '%s custom code restored.', '%s custom code restored.', $counters['untrashed'], 'elementor-pro' ), ]; } return $messages; }, 10, 12 ); } /** * Function register metabox. * * Add meta box for custom-code post. */ private function register_metabox() { if ( ! is_admin() ) { return; } // Remove 'author' meta_box from 'add-new.php', 'author' is required only in list ( enabled via 'supports' arg ). add_action( 'add_meta_boxes_' . self::CPT, function () { remove_meta_box( 'authordiv', self::CPT, 'normal' ); } ); } private function enqueue_assets() { wp_enqueue_style( 'elementor-app-base', $this->get_css_assets_url( 'app-base', null, 'default', true ), [ 'elementor-icons', 'select2', ], ELEMENTOR_VERSION ); wp_register_style( 'select2', $this->get_css_assets_url( 'e-select2', 'assets/lib/e-select2/css/' ), [], '4.0.6-rc.1' ); wp_register_script( 'select2', $this->get_js_assets_url( 'e-select2.full', 'assets/lib/e-select2/js/' ), [ 'jquery', ], '4.0.6-rc.1', true ); wp_register_style( 'elementor-icons', $this->get_css_assets_url( 'elementor-icons', 'assets/lib/eicons/css/' ), [], Icons_Manager::ELEMENTOR_ICONS_VERSION ); wp_enqueue_script( 'react' ); wp_enqueue_script( 'react-dom' ); wp_enqueue_script( 'elementor-app-packages', $this->get_js_assets_url( 'app-packages' ), [ 'wp-i18n', 'react', ], ELEMENTOR_VERSION, true ); add_action( 'elementor-pro/metabox/render', function ( $metabox, $post_id ) { $min_suffix = Utils::is_script_debug() ? '' : '.min'; wp_enqueue_script( 'tipsy', ELEMENTOR_ASSETS_URL . 'lib/tipsy/tipsy' . $min_suffix . '.js', [ 'jquery', ], '1.0.0', true ); $direction_suffix = is_rtl() ? '-rtl' : ''; wp_enqueue_style( 'custom-code', ELEMENTOR_PRO_ASSETS_URL . 'css/modules/custom-code' . $direction_suffix . $min_suffix . '.css', [ 'elementor-app-base', ], ELEMENTOR_PRO_VERSION ); // Load 'admin.js` module JS entry. wp_enqueue_script( 'custom-code-metabox', ELEMENTOR_PRO_ASSETS_URL . 'js/custom-code' . $min_suffix . '.js', [ 'elementor-v2-ui', 'elementor-v2-icons', 'react', 'select2', // Temporary dependency until we will have a better way to load AI app in the admin. 'elementor-ai-admin', ], ELEMENTOR_PRO_VERSION ); $post = [ 'ID' => $post_id, 'post_status' => get_post_status( $post_id ), ]; wp_add_inline_script( 'custom-code-metabox', sprintf( 'elementorProAdmin.customCode.post = %s;', wp_json_encode( $post ) ) ); }, 10, 2 ); } private function add_admin_menu( Admin_Menu_Manager $admin_menu_manager ) { if ( $this->can_use_custom_code() ) { $admin_menu_manager->register( static::MENU_SLUG, new Custom_Code_Menu_Item() ); } else { $admin_menu_manager->register( static::PROMOTION_MENU_SLUG, new Custom_Code_Promotion_Menu_Item() ); } } private function can_use_custom_code() { return ( API::is_license_active() && API::is_licence_has_feature( static::MODULE_NAME, API::BC_VALIDATION_CALLBACK ) || $this->has_custom_code_snippets() ); } private function has_custom_code_snippets() { $existing_snippets = get_posts( [ 'posts_per_page' => 1, // Avoid fetching too much data 'post_type' => static::CPT, ] ); return ! empty( $existing_snippets ); } private function register_documents( Documents_Manager $documents_manager ) { $documents_manager->register_document_type( self::DOCUMENT_TYPE, Document::get_class_full_name() ); } private function register_location( Locations_Manager $location_manager ) { foreach ( array_keys( $this->meta_box->get_location_options() ) as $location ) { $location_manager->register_location( $location, [ 'multiple' => true, 'public' => false, 'edit_in_content' => false, ] ); } } private function maybe_render_blank_state( $which ) { $counts = (array) wp_count_posts( self::CPT ); unset( $counts['auto-draft'] ); if ( ! array_sum( $counts ) ) { /** @var Source_Local $source */ $source = Plugin::elementor()->templates_manager->get_source( 'local' ); $source->maybe_render_blank_state( $which, [ 'post_type' => self::DOCUMENT_TYPE, 'cpt' => self::CPT, 'description' => esc_html__( 'Add pixels, meta tags and any other scripts to your site.', 'elementor-pro' ) . sprintf( '<br><a target="_blank" href="https://go.elementor.com/wp-dash-custom-code">%s</a>', esc_html__( 'Learn more about adding custom code', 'elementor-pro' ) ), 'href' => esc_url( admin_url( '/post-new.php?post_type=' . self::CPT ) ), ] ); } } private function manage_posts_columns( $columns ) { $new = [ self::ADDITIONAL_COLUMN_INSTANCES => esc_html__( 'Instances', 'elementor-pro' ), Custom_Code_Metabox::FIELD_LOCATION => esc_html__( 'Location', 'elementor-pro' ), Custom_Code_Metabox::FIELD_PRIORITY => esc_html__( 'Priority', 'elementor-pro' ), ]; // Insert after 'author'. $keys = array_keys( $columns ); $pos = array_search( 'author', $keys ) + 1; $columns = array_merge( array_slice( $columns, 0, $pos ), $new, array_slice( $columns, $pos ) ); return $columns; } private function manage_posts_custom_column( $column_name, $post_id ) { if ( in_array( $column_name, Custom_Code_Metabox::INPUT_FIELDS ) ) { $value = get_post_meta( $post_id, '_elementor_' . $column_name, true ); if ( Custom_Code_Metabox::FIELD_LOCATION === $column_name ) { $location_labels = $this->meta_box->get_location_labels(); if ( isset( $location_labels[ $value ] ) ) { $value = $location_labels[ $value ]; } } echo esc_html( $value ); } elseif ( self::ADDITIONAL_COLUMN_INSTANCES === $column_name ) { /** @var Conditions_Manager $conditions_manager */ $conditions_manager = Plugin::instance()->modules_manager->get_modules( 'theme-builder' )->get_conditions_manager(); echo esc_html( implode( ', ', $conditions_manager->get_document_instances( $post_id ) ) ); } } private function get_snippets_by_location( $location ) { return get_posts( [ 'numberposts' => -1, 'post_type' => self::CPT, 'meta_query' => [ [ 'key' => '_elementor_' . Custom_Code_Metabox::FIELD_LOCATION, 'value' => $location, ], ], // Order. 'order' => 'ASC', 'orderby' => 'meta_value_num', 'meta_key' => '_elementor_' . Custom_Code_Metabox::FIELD_PRIORITY, ] ); } private function print_snippets( $location ) { // Do not print snippets on safe mode. if ( isset( $_REQUEST['elementor-mode'] ) && 'safe' === $_REQUEST['elementor-mode'] ) { return; } $snippets = $this->get_snippets_by_location( $location ); /** @var \ElementorPro\Modules\ThemeBuilder\Module $theme_builder */ $theme_builder = Plugin::instance()->modules_manager->get_modules( 'theme-builder' ); $documents_by_conditions = $theme_builder->get_conditions_manager()->get_documents_for_location( $location ); $location_manager = $theme_builder->get_locations_manager(); foreach ( $snippets as $snippet ) { // Add snippet to location. // Also handling situation without conditions, bind current snippet id with current location. if ( isset( $documents_by_conditions[ $snippet->ID ] ) || ! get_post_meta( $snippet->ID, '_elementor_conditions', true ) ) { $location_manager->add_doc_to_location( $location, $snippet->ID ); } } elementor_theme_do_location( $location ); } } document.php 0000644 00000005342 14721652711 0007105 0 ustar 00 <?php namespace ElementorPro\Modules\CustomCode; use ElementorPro\Modules\ThemeBuilder\Documents\Theme_Document; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } class Document extends Theme_Document { private static $applied_options = []; public static function get_properties() { $properties = parent::get_properties(); $properties['cpt'] = [ Module::CPT ]; $properties['admin_tab_group'] = ''; $properties['show_in_library'] = false; $properties['support_site_editor'] = false; return $properties; } public static function get_title() { return esc_html__( 'Custom Code', 'elementor-pro' ); } public static function get_type() { return Module::DOCUMENT_TYPE; } public function get_name() { return Module::DOCUMENT_TYPE; } public function print_content() { $content = get_post_meta( $this->post->ID, '_elementor_' . Custom_Code_Metabox::FIELD_CODE, true ) . PHP_EOL; $user_has_permission = current_user_can( Module::CAPABILITY ); $this->apply_snippet_options( get_post_meta( $this->get_id(), '_elementor_' . Custom_Code_Metabox::FILED_EXTRA_OPTIONS, true ) ); if ( $user_has_permission ) { $this->print_snippet_with_elementor_comment( $content ); } else { // PHPCS - the main content of custom code echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } public static function get_create_url() { $query_args = [ 'post_type' => Module::CPT, ]; return add_query_arg( $query_args, admin_url( 'post-new.php' ) ); } private function print_snippet_with_elementor_comment( $content ) { echo implode( PHP_EOL, [ '', '<!--', 'Title: ' . esc_html( $this->post->post_title ), 'Type: ' . Module::CPT, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped 'Author: ' . esc_html( get_the_author_meta( 'display_name', $this->post->post_author ) ), 'Last edited: ' . esc_html( $this->post->post_modified ), '--- The comment is visible only for administrators ---', '-->', '', ] ); // PHPCS - the main content of custom code echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped echo PHP_EOL . '<!-- End of snippet -->' . PHP_EOL; } private function apply_snippet_options( $options ) { if ( ! is_array( $options ) || ! count( $options ) ) { return; } foreach ( $options as $option ) { if ( ! empty( self::$applied_options[ $option ] ) ) { continue; } switch ( $option ) { case Custom_Code_Metabox::INPUT_OPTION_ENSURE_JQUERY: wp_enqueue_script( 'jquery' ); // Ensure jQuery will be first in order. if ( 'wp_footer' === current_filter() ) { wp_print_footer_scripts(); } break; } self::$applied_options[ $option ] = true; } } } admin-menu-items/custom-code-promotion-menu-item.php 0000644 00000005340 14721652711 0016602 0 ustar 00 <?php namespace ElementorPro\Modules\CustomCode\AdminMenuItems; use ElementorPro\License\API; use ElementorPro\Modules\Tiers\AdminMenuItems\Base_Promotion_Template; use ElementorPro\Plugin; use ElementorPro\Modules\CustomCode\Module as Custom_Code_Module; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Custom_Code_Promotion_Menu_Item extends Base_Promotion_Template { public function get_name(): string { return 'custom-code-promotion'; } public function get_cta_url(): string { if ( ! API::active_licence_has_feature( Custom_Code_Module::MODULE_NAME ) ) { $upgrade_url = 'https://go.elementor.com/go-pro-advanced-custom-code/'; return $upgrade_url; } $connect_url = Plugin::instance()->license_admin->get_connect_url( [ 'utm_source' => 'custom-code', 'utm_medium' => 'wp-dash', 'utm_campaign' => 'connect-and-activate-license', ] ); $renew_url = 'https://go.elementor.com/renew-custom-code/'; return API::is_license_expired() ? $renew_url : $connect_url; } public function get_cta_text() { if ( ! API::active_licence_has_feature( Custom_Code_Module::MODULE_NAME ) ) { return esc_html__( 'Upgrade Now', 'elementor-pro' ); } return API::is_license_expired() ? esc_html__( 'Renew now', 'elementor-pro' ) : esc_html__( 'Connect & Activate', 'elementor-pro' ); } public function get_label() { return $this->get_page_title(); } public function get_page_title() { return esc_html__( 'Custom Code', 'elementor-pro' ); } public function get_promotion_title(): string { return sprintf( esc_html__( 'Enjoy Creative Freedom %s with Custom Code', 'elementor-pro' ), '<br />' ); } public function get_video_url(): string { return 'https://www.youtube-nocookie.com/embed/IOovQd1hJUg?si=JLHk3UAexnvTfU1a'; } public function get_promotion_description() { return esc_html__( 'Add Custom Code snippets to your website.', 'elementor-pro' ); } public function get_side_note(): string { return esc_html__( '* Requires an Advanced subscription or higher', 'elementor-pro' ); } /** * @deprecated use get_promotion_description instead * @return void */ public function render_promotion_description() { echo $this->get_promotion_description(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } protected function get_content_lines(): array { return [ esc_html__( 'Add Custom Code snippets anywhere on your website, including the header or footer to measure your page’s performance*', 'elementor-pro' ), esc_html__( 'Use Custom Code to create sophisticated custom interactions to engage visitors', 'elementor-pro' ), esc_html__( 'Leverage Elementor AI to instantly generate Custom Code for Elementor', 'elementor-pro' ), ]; } } admin-menu-items/custom-code-menu-item.php 0000644 00000001515 14721652711 0014556 0 ustar 00 <?php namespace ElementorPro\Modules\CustomCode\AdminMenuItems; use Elementor\Core\Admin\Menu\Interfaces\Admin_Menu_Item; use Elementor\Settings; use ElementorPro\Modules\CustomCode\Module as CustomCodeModule; use ElementorPro\License\API; if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Custom_Code_Menu_Item implements Admin_Menu_Item { const LICENSE_FEATURE_NAME = 'custom_code'; public function get_capability() { return CustomCodeModule::CAPABILITY; } public function get_label() { return esc_html__( 'Custom Code', 'elementor-pro' ); } public function get_parent_slug() { return Settings::PAGE_ID; } public function get_position() { return null; } public function is_visible() { return API::is_licence_has_feature( static::LICENSE_FEATURE_NAME, API::BC_VALIDATION_CALLBACK ); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.3-4ubuntu2.24 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка