plugin_name = $plugin_name; $this->version = $version; $this->library = new Adv_Vis_Ele_Library(); } /** * Register the stylesheets for the admin area. */ public function enqueue_styles() { if (Adv_Vis_Ele_Admin::visiting_plugin_pages()) { if (!wp_style_is('wp-color-picker')) { wp_enqueue_style('wp-color-picker'); } if (!wp_style_is('font-awesome')) { wp_enqueue_style('font-awesome', ADV_VIS_ELE_PLUGIN_URL . 'vendor/fontawesome-5.15.1/css/all.min.css', [], $this->version, 'all'); } if (!wp_style_is($this->plugin_name)) { wp_enqueue_style($this->plugin_name, ADV_VIS_ELE_PLUGIN_URL . 'admin/css/adv-vis-ele-admin.css', [], $this->version, 'all'); } } } /** * Check if we're on any of the plugin pages */ public static function visiting_plugin_pages() { return in_array(get_current_screen()->id, ADV_VIS_ELE_PAGE_SCREEN_IDS) || (get_current_screen()->base === 'post' && get_current_screen()->post_type === 'adv-vis-element'); } /** * Register JavaScript for the admin area. */ public function enqueue_scripts() { if (Adv_Vis_Ele_Admin::visiting_plugin_pages()) { global $pagenow; // disable auto saves switch (get_post_type()) { case 'adv-vis-element': wp_dequeue_script('autosave'); break; } $editing_element = (isset($_GET['post_type']) && $pagenow === 'edit.php' && sanitize_text_field($_GET['post_type']) === 'adv-vis-element') || ($pagenow == 'post.php' && get_post_type() == 'adv-vis-element'); if (!did_action('wp_enqueue_media')) { wp_enqueue_media(); } if (!wp_script_is('jquery')) { wp_enqueue_script('jquery'); } $adv_ce_settings['codeEditor'] = wp_enqueue_code_editor(['type' => 'text/css']); if (!wp_script_is('wp-theme-plugin-editor')) { wp_enqueue_script('wp-theme-plugin-editor', '', ['jquery'], false, true); } if (!wp_style_is('wp-codemirror')) { wp_enqueue_style('wp-codemirror'); } if (!wp_script_is('wp-color-picker')) { wp_enqueue_script('wp-color-picker'); } if (!wp_script_is('wp-color-picker-alpha')) { wp_enqueue_script('wp-color-picker-alpha', ADV_VIS_ELE_PLUGIN_URL . 'admin/js/wp-color-picker-alpha.js', ['wp-color-picker'], '3.0.0', true); } if (!wp_script_is('popper-js')) { wp_enqueue_script('popper-js', ADV_VIS_ELE_PLUGIN_URL . 'vendor/tippyjs/popper.min.js', [], $this->version, true); } if (!wp_script_is('tippy-js')) { wp_enqueue_script('tippy-js', ADV_VIS_ELE_PLUGIN_URL . 'vendor/tippyjs/tippy-bundle.umd.min.js', [], $this->version, true); } if (!wp_script_is($this->plugin_name)) { wp_enqueue_script($this->plugin_name, ADV_VIS_ELE_PLUGIN_URL . 'admin/js/adv-vis-ele-admin.js', ['jquery'], $this->version, true); } $is_add_new_btn = is_admin() && $editing_element; $library_ordering = get_user_meta(get_current_user_id(), 'adv_vis_ele_library_ordering', true); if (empty($library_ordering)) { $library_ordering = 'asc'; add_user_meta(get_current_user_id(), 'adv_vis_ele_library_ordering', $library_ordering); } wp_localize_script($this->plugin_name, 'adv_vis_ele_admin_vars', [ 'nonce' => wp_create_nonce('ave_ajax'), 'site_url' => site_url(), 'ajax_url' => admin_url('admin-ajax.php'), 'admin_url' => admin_url('admin.php'), 'wp_admin_url' => admin_url(), 'is_pro' => wpave_fs()->can_use_premium_code(), 'translations' => Adv_Vis_Ele_i18n::$translations, 'auto_play_library_videos' => get_option('adv_vis_ele_auto_play_library_videos') == 'on' ? 1 : 0, 'is_add_new_btn' => $is_add_new_btn, 'cm_settings' => $adv_ce_settings, 'library_ordering' => $library_ordering, 'dev_update_finished' => isset($_GET['adv-vis-ele-library-action']) && sanitize_text_field($_GET['adv-vis-ele-library-action']) === 'update-finished-dev', 'dynamic_setting_delimiter_start' => Adv_Vis_Ele_Library::$dynamic_settings_delimiter_start, 'dynamic_setting_delimiter_end' => Adv_Vis_Ele_Library::$dynamic_settings_delimiter_end ]); } } /** * Creates the plugin configuration page(s) */ public function create_plugin_admin_page() { add_menu_page('Advanced Visual Elements', 'Advanced Visual Elements', 'manage_options', 'adv-vis-ele', function () { include_once 'partials/adv-vis-ele-admin-library.php'; }, ADV_VIS_ELE_PLUGIN_URL . 'img/adv-vis-ele-dashicon.png'); add_submenu_page('adv-vis-ele', 'Advanced Visual Elements Library', 'Library', 'manage_options', 'adv-vis-ele', function () { include_once 'partials/adv-vis-ele-admin-library.php'; }); add_submenu_page('adv-vis-ele', 'Advanced Visual Shortcodes', 'Shortcodes', 'manage_options', 'edit.php?post_type=adv-vis-element'); add_submenu_page('adv-vis-ele', 'Advanced Visual Elements Settings', 'Settings', 'manage_options', 'adv-vis-ele-settings', function () { include_once 'partials/adv-vis-ele-admin-settings.php'; }); } /** * Add element ID when publishing it for the first time */ public function on_publish_element($post_id) { if (isset($_POST['element-id'])) { $element_id = sanitize_text_field($_POST['element-id']); } if (!empty($element_id)) { // this means we are in editor update_post_meta($post_id, 'adv-vis-ele-element_id', $element_id); update_post_meta($post_id, 'adv-vis-ele-custom_css', sanitize_textarea_field($_POST['adv-vis-ele-editor-custom-css'])); update_post_meta($post_id, 'adv-vis-ele-mobile_breakpoint', sanitize_text_field($_POST['adv-vis-ele-editor-mobile-breakpoint'])); update_post_meta($post_id, 'adv-vis-ele-disable_on_mobile', isset($_POST['adv-vis-ele-editor-disable-on-mobile']) ? 'on' : false); update_post_meta($post_id, 'adv-vis-ele-container_styles', sanitize_textarea_field($_POST['adv-vis-ele-editor-container-styles'])); update_post_meta($post_id, 'adv-vis-ele-container_styles_vertical', sanitize_textarea_field($_POST['adv-vis-ele-editor-container-styles-vertical'])); } if (isset($_POST['adv-vis-ele-editor-settings'])) { $settings = []; foreach ($_POST['adv-vis-ele-editor-settings'] as $key => $setting) { $key = sanitize_text_field($key); if (is_array($setting)) { $settings[$key] = array_map('wp_kses_post', $setting); } else { $settings[$key] = wp_kses_post($setting); } } } if (!empty($_POST['adv-vis-ele-editor-settings-dynamic'])) { foreach ($_POST['adv-vis-ele-editor-settings-dynamic'] as $setting_name => $dynamic_setting) { $setting_name = sanitize_text_field($setting_name); $settings[$setting_name] = sanitize_text_field($dynamic_setting); } } if (isset($_POST['adv-vis-ele-editor-settings-bool'])) { foreach ($_POST['adv-vis-ele-editor-settings-bool'] as $bool_name => $bool_value) { $bool_name = sanitize_text_field($bool_name); $settings[$bool_name] = isset($_POST['adv-vis-ele-editor-settings'][$bool_name]) ? sanitize_text_field($_POST['adv-vis-ele-editor-settings'][$bool_name]) : false; } } if (!isset($settings) || !isset($element_id)) { return; } if (!empty($settings) && !empty($element_id)) { $post_meta = Adv_Vis_Ele_Admin::get_element_meta_settings($post_id); $saving = []; foreach ($settings as $setting_name => $setting_value) { $setting = $this->library->get_element_setting($element_id, $setting_name); if ($setting) { if ($setting->license !== 'free') { if (wpave_fs()->can_use_premium_code()) { $saving[$setting_name] = Adv_Vis_Ele_Admin::filter_setting($setting, $setting_value); } else { if (!empty($post_meta)) { $saving[$setting_name] = $post_meta[$setting_name]; } else { $saving[$setting_name] = $setting->default; } } } else { $saving[$setting_name] = Adv_Vis_Ele_Admin::filter_setting($setting, $setting_value); } } } Adv_Vis_Ele_Admin::save_element_meta_settings($saving, $post_id); } } /** * Get meta settings */ public static function get_element_meta_settings($post_id) { $meta_settings = get_post_meta($post_id, 'adv-vis-ele-editor-settings', true); if (empty($meta_settings)) { return []; } // WordPress automatically adds slashes before they're saved to post meta foreach ($meta_settings as $key => $meta_setting) { if (is_array($meta_setting)) { $meta_settings[$key] = array_map('wp_unslash', $meta_setting); } else { $meta_settings[$key] = wp_unslash($meta_setting); } } return $meta_settings; } /** * Save meta settings */ public static function save_element_meta_settings($saving, $post_id) { return update_post_meta($post_id, 'adv-vis-ele-editor-settings', $saving); } /** * Filter settings */ public static function filter_setting($setting, $setting_value) { if ($setting->type === 'number') { if (!empty($setting->min) && !empty($setting->max)) { $value = Adv_Vis_Ele_Helpers::clamp($setting_value, $setting->min, $setting->max); } else { $value = $setting_value; } } else if ($setting->type === 'boolean') { if (strtolower($setting_value) === 'on' || $setting_value === '1' || $setting_value === true) { return true; } return false; } else { $value = $setting_value; } return $value; } /** * Add shortcodes to element lists */ public function add_shortcodes_to_element_list($defaults) { $defaults['ave_element_id'] = 'Library Element'; $defaults['ave_shortcode'] = 'Shortcode/PHP code'; return $defaults; } /** * Populate shortcodes in element list */ public function populate_shortcodes_in_element_list($column_name, $post_id) { if ($column_name === 'ave_shortcode') { echo '
[ave-element id="' . (int)$post_id . '"]<?php echo do_shortcode('[ave-element id="' . (int)$post_id . '"]'); ?>Library version library->library_version); ?>
Total elements library->library_info); ?>
DEV Update Library Reset Library