File manager - Edit - /home/matthif/www/wp-content/languages/metabox.tar
Back
main.php 0000666 00000014215 15226760533 0006221 0 ustar 00 <?php /** * Page settings metabox. * * @package Neve */ namespace Neve\Admin\Metabox; /** * Class Metabox * * @package Neve\Admin\Metabox */ class Main extends Controls_Base { /** * Add controls. */ public function add_controls() { $this->add_layout_controls(); $this->add_control( new Controls\Separator( 'neve_meta_separator', array( 'priority' => 20 ) ) ); $this->add_content_toggles(); $this->add_control( new Controls\Separator( 'neve_meta_separator', array( 'priority' => 45 ) ) ); $this->add_content_width(); } /** * Add layout controls. */ private function add_layout_controls() { $this->add_control( new Controls\Radio( 'neve_meta_container', array( 'default' => 'default', 'choices' => array( 'default' => __( 'Customizer Setting', 'neve' ), 'contained' => __( 'Contained', 'neve' ), 'full-width' => __( 'Full Width', 'neve' ), ), 'label' => __( 'Container', 'neve' ), ) ) ); $position_default = 'default'; $this->add_control( new Controls\Radio( 'neve_meta_sidebar', array( 'default' => $position_default, 'choices' => array( 'default' => __( 'Customizer Setting', 'neve' ), 'left' => __( 'Left Sidebar', 'neve' ), 'right' => __( 'Right Sidebar', 'neve' ), 'full-width' => __( 'No Sidebar', 'neve' ), ), 'label' => __( 'Sidebar', 'neve' ), 'priority' => 15, ) ) ); } /** * Add content toggles. */ private function add_content_toggles() { $content_controls = array( 'neve_meta_disable_header' => array( 'default' => 'off', 'label' => __( 'Components', 'neve' ), 'input_label' => __( 'Disable Header', 'neve' ), 'priority' => 25, ), 'neve_meta_disable_title' => array( 'default' => 'off', 'input_label' => __( 'Disable Title', 'neve' ), 'active_callback' => array( $this, 'hide_on_single_product' ), 'priority' => 30, ), 'neve_meta_disable_featured_image' => array( 'default' => 'off', 'input_label' => __( 'Disable Featured Image', 'neve' ), 'active_callback' => array( $this, 'hide_on_single_page_and_product' ), 'priority' => 35, ), 'neve_meta_disable_footer' => array( 'default' => 'off', 'input_label' => __( 'Disable Footer', 'neve' ), 'priority' => 40, ), ); $default_control_args = array( 'default' => 'off', 'label' => '', 'input_label' => '', 'active_callback' => '__return_true', 'priority' => 10, ); foreach ( $content_controls as $control_id => $args ) { $args = wp_parse_args( $args, $default_control_args ); $this->add_control( new Controls\Checkbox( $control_id, array( 'default' => $args['default'], 'label' => $args['label'], 'input_label' => $args['input_label'], 'active_callback' => $args['active_callback'], 'priority' => $args['priority'], ) ) ); } } /** * Add content width control. */ private function add_content_width() { $enabled_default = 'off'; $width_default = self::is_post() ? 70 : 100; $this->add_control( new Controls\Checkbox( 'neve_meta_enable_content_width', array( 'default' => $enabled_default, 'label' => __( 'Content Width', 'neve' ) . ' (%)', 'input_label' => __( 'Enable Individual Content Width', 'neve' ), 'priority' => 50, ) ) ); $this->add_control( new Controls\Range( 'neve_meta_content_width', array( 'default' => $width_default, 'min' => 50, 'max' => 100, 'hidden' => self::hide_content_width(), 'depends_on' => 'neve_meta_enable_content_width', 'priority' => 55, ) ) ); } /** * Hide content width. * * @return bool */ public static function hide_content_width() { if ( self::is_new_page() ) { return false; } if ( ! isset( $_GET['post'] ) ) { return true; } $meta = get_post_meta( (int) $_GET['post'], 'neve_meta_enable_content_width', true ); if ( empty( $meta ) && self::is_checkout() ) { return false; } if ( empty( $meta ) || $meta === 'off' ) { return true; } return false; } /** * Callback to hide on single product edit page. * * @return bool */ public function hide_on_single_product() { if ( isset( $_GET['post_type'] ) && $_GET['post_type'] === 'product' ) { return false; } if ( ! isset( $_GET['post'] ) ) { return true; } $post_type = get_post_type( (int) $_GET['post'] ); if ( $post_type !== 'product' ) { return true; } return false; } /** * Callback to hide on single product/page edit page * * @return bool */ public function hide_on_single_page_and_product() { if ( isset( $_GET['post_type'] ) && ( $_GET['post_type'] === 'page' || $_GET['post_type'] === 'product' ) ) { return false; } if ( ! isset( $_GET['post'] ) ) { return true; } $post_type = get_post_type( (int) $_GET['post'] ); if ( $post_type !== 'page' && $post_type !== 'product' ) { return true; } return false; } /** * Check if we're adding a new post of type `page`. * * @return bool */ public static function is_new_page() { global $pagenow; if ( $pagenow !== 'post-new.php' ) { return false; } if ( ! isset( $_GET['post_type'] ) ) { return false; } if ( ( $_GET['post_type'] !== 'page' ) ) { return false; } return true; } /** * Check if is checkout. */ public static function is_checkout() { if ( ! class_exists( 'WooCommerce', false ) ) { return false; } if ( ! isset( $_GET['post'] ) ) { return false; } if ( $_GET['post'] === get_option( 'woocommerce_checkout_page_id' ) ) { return true; } return false; } /** * Check if is post. */ public static function is_post() { global $pagenow; // New post. if ( $pagenow === 'post-new.php' && ! isset( $_GET['post_type'] ) ) { return true; } if ( ! isset( $_GET['post'] ) ) { return false; } if ( get_post_type( absint( $_GET['post'] ) ) === 'post' ) { return true; } return false; } } manager.php 0000666 00000030314 15226760533 0006705 0 ustar 00 <?php /** * Page settings metabox. * * @package Neve */ namespace Neve\Admin\Metabox; use Neve\Core\Settings\Config; use Neve\Core\Settings\Mods; use Neve\Customizer\Defaults\Layout; use Neve\Customizer\Defaults\Single_Post; use Neve\Customizer\Options\Layout_Single_Post; use Neve\Views\Post_Layout; use Neve\Core\Supported_Post_Types; /** * Class Manager * * @package Neve\Admin\Metabox */ final class Manager { use Single_Post; use Layout; /** * Control instances. * * @var array */ private $controls = array(); /** * Control classes to get controls from. * * @var array */ private $control_classes; /** * Init function */ public function init() { add_action( 'add_meta_boxes', array( $this, 'add' ) ); add_action( 'admin_init', array( $this, 'define_controls' ) ); add_action( 'admin_init', array( $this, 'load_controls' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) ); add_action( 'save_post', array( $this, 'save' ) ); /** * Gtb meta */ add_action( 'init', array( $this, 'neve_register_meta' ) ); add_action( 'enqueue_block_editor_assets', array( $this, 'meta_sidebar_script_enqueue' ) ); } /** * Define the controls. */ public function define_controls() { $this->control_classes = array( 'Neve\\Admin\\Metabox\\Main', ); $this->control_classes = apply_filters( 'neve_filter_metabox_controls', $this->control_classes ); } /** * Instantiate the controls and actually load them into the control manager. */ public function load_controls() { if ( empty( $this->control_classes ) ) { return; } foreach ( $this->control_classes as $control_manager ) { $control_instance = new $control_manager(); if ( ! $control_instance instanceof Controls_Base ) { continue; } $control_instance->init(); $this->controls = array_merge( $this->controls, $control_instance->get_controls() ); } $this->order_by_priority(); } /** * The metabox content. */ public function render_controls() { global $post; foreach ( $this->controls as $control ) { if ( method_exists( $control, 'render' ) ) { $control->render( $post->ID ); } } } /** * Save metabox content. * * @param int $post_id the post id. */ public function save( $post_id ) { foreach ( $this->controls as $control ) { if ( method_exists( $control, 'save' ) ) { $control->save( $post_id ); } } } /** * Register meta box to control layout on pages and posts. */ public function add() { $post_type = 'Neve'; $post_type_from_db = get_post_type(); if ( $post_type_from_db ) { $post_type = ucfirst( $post_type_from_db ); } add_meta_box( 'neve-page-settings', sprintf( /* translators: %s - post type */ __( '%s Settings', 'neve' ), $post_type ), array( $this, 'render_metabox' ), array( 'post', 'page', 'product' ), 'side', 'default', array( '__back_compat_meta_box' => true, ) ); if ( $this->is_gutenberg_active() ) { add_meta_box( 'neve-page-settings-notice', sprintf( /* translators: %s - post type */ __( '%s Settings', 'neve' ), $post_type ), array( $this, 'render_metabox_notice' ), Supported_Post_Types::get( 'block_editor' ), 'side', 'default', array( '__back_compat_meta_box' => false, ) ); } } /** * Detect if is gutenberg editor. * * @return bool */ private function is_gutenberg_active() { global $current_screen; if ( method_exists( $current_screen, 'is_block_editor' ) ) { return $current_screen->is_block_editor(); } return false; } /** * The metabox content. */ public function render_metabox() { $this->render_controls(); } /** * Render the metabox notice. */ public function render_metabox_notice() { echo '<div class="nv-meta-notice-wrapper">'; echo '<h4>' . esc_html__( 'Page Settings are now accessible from the top bar', 'neve' ) . '</h4>'; printf( /* translators: %1$s - Keyboard shortcut. %2&s - svg icon */ esc_html__( 'Click the %1$s icon in the top bar or use the keyboard shortcut ( %2$s ) to customise the layout settings for this page', 'neve' ), apply_filters( 'ti_wl_theme_is_localized', false ) ? '<span class="dashicons dashicons-hammer"></span>' : '<svg width="17" height="24" viewBox="0 0 17 24" fill="none" xmlns="http://www.w3.org/2000/svg"> <path d="M4.77822 10.2133V19.3287H0.118347V0.802224C0.118347 0.712594 0.145598 0.649854 0.200099 0.614002C0.254601 0.578149 0.354519 0.622964 0.499857 0.748446L12.1359 10.2133V1.04422H16.7958V19.5976C16.7958 19.7051 16.7685 19.7724 16.714 19.7992C16.6595 19.8261 16.5596 19.7768 16.4143 19.6514L4.77822 10.2133Z"/> <rect x="0.118347" y="22.3334" width="16.6774" height="1.51613"/> </svg>', '<strong>SHIFT + ALT + S</strong> ' . esc_html__( 'or', 'neve' ) . ' <strong>control + option + S</strong>' ); echo '</div>'; } /** * Enqueue scripts and styles. */ public function enqueue() { if ( $this->is_gutenberg_active() ) { return; } $screen = get_current_screen(); if ( ! is_object( $screen ) ) { return; } if ( $screen->base !== 'post' ) { return; } wp_register_script( 'neve-metabox', NEVE_ASSETS_URL . 'js/build/all/metabox.js', array( 'jquery' ), NEVE_VERSION, true ); wp_localize_script( 'neve-metabox', 'neveMetabox', $this->get_localization() ); wp_enqueue_script( 'neve-metabox' ); } /** * Localize the Metabox script. * * @return array */ private function get_localization() { return array(); } /** * Order the controls by given priority. */ private function order_by_priority() { $order = array(); foreach ( $this->controls as $key => $control_object ) { $order[ $key ] = $control_object->priority; } array_multisort( $order, SORT_ASC, $this->controls ); } /** * Register meta */ public function neve_register_meta() { $meta_sidebar_controls = apply_filters( 'neve_sidebar_meta_controls', [ [ 'id' => 'neve_meta_sidebar', 'type' => 'radio', ], [ 'id' => 'neve_meta_container', 'type' => 'button-group', ], [ 'id' => 'neve_meta_enable_content_width', 'type' => 'checkbox', ], [ 'id' => 'neve_meta_content_width', 'type' => 'range', ], [ 'id' => 'neve_meta_title_alignment', 'type' => 'button-group', ], [ 'id' => 'neve_meta_author_avatar', 'type' => 'checkbox', ], [ 'id' => 'neve_post_elements_order', 'type' => 'sortable-list', ], [ 'id' => 'neve_meta_disable_header', 'type' => 'checkbox', ], [ 'id' => 'neve_meta_disable_footer', 'type' => 'checkbox', ], [ 'id' => 'neve_meta_disable_title', 'type' => 'checkbox', ], ] ); foreach ( $meta_sidebar_controls as $control ) { $type = 'string'; if ( $control['type'] === 'range' ) { $type = 'integer'; } $post_type = ''; if ( array_key_exists( 'post_type', $control ) ) { $post_type = $control['post_type']; } $meta_settings = array( 'show_in_rest' => true, 'type' => $type, 'single' => true, 'sanitize_callback' => 'sanitize_text_field', 'auth_callback' => function () { return current_user_can( 'edit_posts' ); }, ); register_post_meta( $post_type, $control['id'], $meta_settings ); } } /** * Register the metabox sidebar. */ public function meta_sidebar_script_enqueue() { global $post_type, $pagenow; $do_not_load_on = [ 'widgets.php', 'customize.php' ]; // $post_type returns "page" on widgets.php and on customize.php so we need to check this separately. if ( in_array( $pagenow, $do_not_load_on, true ) || ! in_array( $post_type, Supported_Post_Types::get( 'block_editor' ) ) ) { return false; } $dependencies = ( include get_template_directory() . '/assets/apps/metabox/build/index.asset.php' ); wp_enqueue_script( 'neve-meta-sidebar', trailingslashit( get_template_directory_uri() ) . 'assets/apps/metabox/build/index.js', $dependencies['dependencies'], $dependencies['version'], true ); if ( function_exists( 'wp_set_script_translations' ) ) { wp_set_script_translations( 'neve-meta-sidebar', 'neve' ); } $container = $post_type === 'post' ? Mods::get( Config::MODS_SINGLE_POST_CONTAINER_STYLE, 'contained' ) : Mods::get( Config::MODS_DEFAULT_CONTAINER_STYLE, 'contained' ); $editor_width = Mods::get( Config::MODS_CONTAINER_WIDTH ); $advanced_layout = Mods::get( Config::MODS_ADVANCED_LAYOUT_OPTIONS, true ); $single_width = $post_type === 'post' ? Mods::get( Config::MODS_SINGLE_CONTENT_WIDTH, $this->sidebar_layout_width_default( Config::MODS_SINGLE_CONTENT_WIDTH ) ) : Mods::get( Config::MODS_OTHERS_CONTENT_WIDTH, $this->sidebar_layout_width_default( Config::MODS_OTHERS_CONTENT_WIDTH ) ); $content_width = $advanced_layout ? $single_width : Mods::get( Config::MODS_SITEWIDE_CONTENT_WIDTH, $this->sidebar_layout_width_default( Config::MODS_SITEWIDE_CONTENT_WIDTH ) ); $editor_width = isset( $editor_width['desktop'] ) ? (int) $editor_width['desktop'] : 1170; $post_elements_default_order = $this->get_post_elements_default_order(); $show_avatar = $this->get_author_avatar_state(); $reading_time = $this->get_reading_time_state(); $post_type_details = get_post_type_object( $post_type ); $post_type_label = esc_html( $post_type_details->labels->singular_name ); $localized_data = apply_filters( 'neve_meta_sidebar_localize_filter', array( 'actions' => array( 'neve_meta_content_width' => array( 'container' => $container, 'editor' => $editor_width, 'content' => $content_width, ), ), 'elementsDefaultOrder' => $post_elements_default_order, 'avatarDefaultState' => $show_avatar, 'readingTimeDefaultState' => $reading_time, 'postTypeLabel' => $post_type_label, 'isCoverLayout' => Layout_Single_Post::is_cover_layout(), ) ); wp_localize_script( 'neve-meta-sidebar', 'metaSidebar', $localized_data ); wp_enqueue_style( 'neve-meta-sidebar-css', // Handle. trailingslashit( get_template_directory_uri() ) . 'assets/apps/metabox/build/index.css', array( 'wp-edit-blocks' ), NEVE_VERSION ); } /** * Get the value of elements order from customizer. * * @return string */ private function get_post_elements_default_order() { $default_order = $this->post_ordering(); $content_order = get_theme_mod( 'neve_layout_single_post_elements_order', wp_json_encode( $default_order ) ); if ( ! is_string( $content_order ) ) { $content_order = wp_json_encode( $default_order ); } $content_order = json_decode( $content_order, true ); if ( empty( $content_order ) ) { return wp_json_encode( $content_order ); } $is_cover_layout = Layout_Single_Post::is_cover_layout(); $title_meta_index = array_search( 'title-meta', $content_order ); if ( $title_meta_index !== false && ! $is_cover_layout ) { $content_order[ $title_meta_index ] = 'title'; $next_index = $title_meta_index + 1; $content_order = array_merge( array_slice( $content_order, 0, $next_index, true ), array( 'meta' ), array_slice( $content_order, $next_index, null, true ) ); } return wp_json_encode( $content_order ); } /** * Get the value of author avatar display from customizer. * * @return bool */ private function get_author_avatar_state() { $show_avatar = get_theme_mod( 'neve_author_avatar', false ); return get_theme_mod( 'neve_single_post_author_avatar', $show_avatar ); } /** * Get the value of Reading Time visibility from customizer. * * @return bool */ private function get_reading_time_state() { $meta_fields = get_theme_mod( 'neve_single_post_meta_fields', self::get_default_single_post_meta_fields() ); if ( is_string( $meta_fields ) ) { $meta_fields = json_decode( $meta_fields, true ); } if ( ! is_array( $meta_fields ) ) { return false; } foreach ( $meta_fields as $args ) { if ( ! array_key_exists( 'slug', $args ) || ! array_key_exists( 'visibility', $args ) || $args['slug'] !== 'reading' ) { continue; } return $args['visibility'] === 'yes'; } return false; } } controls_base.php 0000666 00000001424 15226760533 0010130 0 ustar 00 <?php /** * Page settings metabox. * * @package Neve */ namespace Neve\Admin\Metabox; use Neve\Admin\Metabox\Controls\Control_Base; /** * Class Metabox_Controls_Base * * @package Neve\Admin\Metabox */ abstract class Controls_Base { /** * Controls. * * @var array */ private $controls = array(); /** * Init function */ public function init() { $this->add_controls(); } /** * Add controls. */ abstract protected function add_controls(); /** * Add the control. * * @param Controls\Control_Base|Object $control the control object. */ public function add_control( $control ) { array_push( $this->controls, $control ); } /** * Get the controls. * * @return array */ public function get_controls() { return $this->controls; } } controls/radio.php 0000666 00000002157 15226760533 0010240 0 ustar 00 <?php /** * Metabox radio button control. * * @package Neve\Admin\Metabox\Controls */ namespace Neve\Admin\Metabox\Controls; /** * Class Radio * * @package Neve\Admin\Metabox\Controls */ class Radio extends Control_Base { /** * Control type. * * @var string */ public $type = 'radio'; /** * Render control. * * @return void */ public function render_content( $post_id ) { $selected = $this->get_value( $post_id ); $markup = '<style>#neve-page-settings label{ display: block; margin-bottom: 5px;}</style>'; $markup .= '<p>'; foreach ( $this->settings['choices'] as $value => $choice ) { $markup .= '<label for="' . esc_attr( $this->id . '_' . $value ) . '">'; $markup .= '<input type="radio" value="' . esc_attr( $value ) . '" id="' . esc_attr( $this->id . '_' . $value ) . '" name="' . esc_attr( $this->id ) . '"'; $markup .= checked( $selected ? $selected : $this->settings['default'], $value, false ); $markup .= '/>'; $markup .= esc_html( $choice ) . '</label>'; } $markup .= '</p>'; echo $markup; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } controls/checkbox.php 0000666 00000001752 15226760533 0010730 0 ustar 00 <?php /** * Metabox radio button control. * * @package Neve\Admin\Metabox\Controls */ namespace Neve\Admin\Metabox\Controls; /** * Class Checkbox * * @package Neve\Admin\Metabox\Controls */ class Checkbox extends Control_Base { /** * Control type. * * @var string */ public $type = 'checkbox'; /** * Render control. * * @return void */ public function render_content( $post_id ) { $value = $this->get_value( $post_id ); $markup = ''; $markup .= '<p>'; $markup .= '<div class="checkbox-toggle-wrap">'; $markup .= '<label for="' . esc_attr( $this->id ) . '">'; $markup .= '<input type="checkbox" id="' . esc_attr( $this->id ) . '" name="' . esc_attr( $this->id ) . '" '; if ( $value === 'on' ) { $markup .= ' checked="checked" '; } $markup .= '/>'; $markup .= esc_html( $this->settings['input_label'] ) . '</label>'; $markup .= '</div>'; $markup .= '</p>'; echo $markup; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } controls/separator.php 0000666 00000000651 15226760533 0011137 0 ustar 00 <?php /** * Metabox separator. * * @package Neve\Admin\Metabox\Controls */ namespace Neve\Admin\Metabox\Controls; /** * Class Separator * * @package Neve\Admin\Metabox\Controls */ class Separator extends Control_Base { /** * Control type. * * @var string */ public $type = 'separator'; /** * Render control. * * @return void */ public function render_content( $post_id ) { echo '<hr/>'; } } controls/range.php 0000666 00000003340 15226760533 0010231 0 ustar 00 <?php /** * Metabox range control. * * @package Neve\Admin\Metabox\Controls */ namespace Neve\Admin\Metabox\Controls; /** * Class Range * * @package Neve\Admin\Metabox\Controls */ class Range extends Control_Base { /** * Control type. * * @var string */ public $type = 'range'; /** * Render control. * * @return void */ public function render_content( $post_id ) { $value = $this->get_value( $post_id ); $class = 'neve-range-input '; $dependency = ''; if ( $this->settings['hidden'] === true ) { $class .= ' neve-hidden'; } if ( isset( $this->settings['depends_on'] ) ) { $dependency .= ' data-depends=' . esc_attr( $this->settings['depends_on'] ); $class .= ' neve-dependent'; } $markup = ' <style> .neve-range-input{display: flex; align-items: center;} .neve-range-input .nv-range{flex-grow: 1; margin-right: 5px;} .neve-range-input .nv-number{min-width: 0; margin-left: auto;} .neve-range-input.neve-hidden{display: none;} </style>'; $markup .= '<p class="' . esc_attr( $class ) . '" ' . esc_attr( $dependency ) . ' >'; $markup .= '<input type="range" value="' . esc_attr( $value ) . '" id="' . esc_attr( $this->id ) . '-range" class="nv-range" name="' . esc_attr( $this->id ) . '" min="' . esc_attr( $this->settings['min'] ) . '" max="' . esc_attr( $this->settings['max'] ) . '" >'; $markup .= '<input type="number" value="' . esc_attr( $value ) . '" id="' . esc_attr( $this->id ) . '" class="nv-number" name="' . esc_attr( $this->id ) . '" min="' . esc_attr( $this->settings['min'] ) . '" max="' . esc_attr( $this->settings['max'] ) . '" >'; $markup .= '</p>'; echo $markup; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } } controls/control_base.php 0000666 00000010773 15226760533 0011617 0 ustar 00 <?php /** * Abstract class to be used as base for metabox controls. * * @package Neve\Admin\Metabox\Controls */ namespace Neve\Admin\Metabox\Controls; /** * Class Control_Base * * @package Neve\Admin\Metabox\Controls */ abstract class Control_Base { /** * Control id. * * @var string */ public $id = ''; /** * Control settings. * * @var array */ public $settings = array(); /** * Control type [MUST BE DEFINED] * * @var string */ public $type = ''; /** * Control Priority * * @var int */ public $priority = 10; /** * Control_Base constructor. * * @param string $id control id. * @param array $settings control settings. */ public function __construct( $id, $settings ) { if ( empty( $this->type ) ) { return; } $this->id = $id; $this->settings = $settings; if ( isset( $settings['priority'] ) ) { $this->priority = $settings['priority']; } } /** * Render function for the control. */ public function render( $post_id ) { if ( empty( $this->type ) ) { return; } if ( ! $this->should_render() ) { return; } $this->render_label(); $this->render_content( $post_id ); wp_nonce_field( 'neve_meta_box_nonce', 'neve_meta_box_process' ); } /** * Determine if a control should be visible or not. * * @return bool */ private function should_render() { if ( ! array_key_exists( 'active_callback', $this->settings ) ) { return true; } if ( empty( $this->settings['active_callback'] ) ) { return true; } $object = $this->settings['active_callback'][0]; $method = $this->settings['active_callback'][1]; if ( method_exists( $object, $method ) ) { return $object->$method(); } return true; } /** * Render control label. * * @return void */ protected function render_label() { $label = array_key_exists( 'label', $this->settings ) ? $this->settings['label'] : ''; if ( empty( $label ) ) { return; } $control_label = ''; $control_label .= '<p class="post-attributes-label-wrapper">'; $control_label .= '<span class="post-attributes-label">' . esc_html( $label ) . '</span>'; $control_label .= '</p>'; echo wp_kses_post( $control_label ); } /** * Render control. * * @return void */ abstract public function render_content( $post_id ); /** * Save control data. * * @param int $post_id Post id. * * @return void */ final public function save( $post_id ) { if ( ! isset( $_POST['neve_meta_box_process'] ) ) { return; } if ( ! wp_verify_nonce( sanitize_key( $_POST['neve_meta_box_process'] ), 'neve_meta_box_nonce' ) ) { return; } if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } if ( ! current_user_can( 'edit_posts' ) ) { return; } if ( isset( $_POST[ $this->id ] ) ) { $value = $this->sanitize_value( wp_unslash( $_POST[ $this->id ] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized // Remove post meta on default. if ( $value === $this->settings['default'] && $this->id !== 'neve_meta_content_width' ) { delete_post_meta( $post_id, $this->id ); return; } // Update post meta on other values. update_post_meta( $post_id, $this->id, $value ); return; } else { if ( $this->id === 'neve_meta_enable_content_width' ) { update_post_meta( $post_id, 'neve_meta_enable_content_width', 'off' ); } else { delete_post_meta( $post_id, $this->id ); } return; } } /** * Sanitize the value. * * @param int|string $value the value to sanitize. * * @return int|string */ protected function sanitize_value( $value ) { switch ( $this->type ) { case 'radio': $allowed_values = $this->settings['choices']; if ( ! array_key_exists( $value, $allowed_values ) ) { return esc_html( $this->settings['default'] ); } return sanitize_text_field( $value ); case 'checkbox': $allowed_values = array( 'on', 'off' ); if ( ! in_array( $value, $allowed_values, true ) ) { return esc_html( $this->settings['default'] ); } return sanitize_text_field( $value ); case 'range': return absint( $value ); case 'input': return sanitize_text_field( $value ); case 'separator': default: break; } return sanitize_text_field( $value ); } /** * Get the value. * * @param int $post_id the post id. * * @return mixed */ final protected function get_value( $post_id ) { $value = get_post_meta( $post_id, $this->id, true ); return ! empty( $value ) ? $value : $this->settings['default']; } }
| ver. 1.4 |
Github
|
.
| PHP 5.4.45 | Generation time: 0 |
proxy
|
phpinfo
|
Settings