hooks(); } /** * Add the core admin hooks. * * @access private * @since 1.0 * @static */ private function hooks() { global $pagenow; //phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification not required here. if($pagenow == 'options-general.php' && isset($_REQUEST['page']) && !empty($_REQUEST['page']) && $_REQUEST['page'] == 'table-of-contents') { add_action( 'admin_head', array( $this,'_clean_other_plugins_stuff' ) ); } add_action( 'admin_init', array( $this, 'registerScripts' ) ); add_action( 'admin_menu', array( $this, 'menu' ) ); add_action( 'init', array( $this, 'registerMetaboxes' ), 99 ); add_filter( 'plugin_action_links_' . EZ_TOC_BASE_NAME, array( $this, 'pluginActionLinks' ), 10, 2 ); add_action( 'admin_enqueue_scripts', array( $this, 'load_scripts' ) ); add_action('wp_ajax_eztoc_send_query_message', array( $this, 'eztoc_send_query_message')); add_action('wp_ajax_eztoc_migrate_tocplus', array( $this, 'eztoc_migrate_tocplus')); } /** * Attach to admin_head hook to hide all admin notices. * * @scope public * @since 2.0.33 * @return void * @uses remove_all_actions() */ public function _clean_other_plugins_stuff() { remove_all_actions('admin_notices'); remove_all_actions('network_admin_notices'); remove_all_actions('all_admin_notices'); remove_all_actions('user_admin_notices'); } /** * Callback to add the Settings link to the plugin action links. * * @access private * @since 1.0 * @static * * @param $links * @param $file * * @return array */ public function pluginActionLinks( $links, $file ) { $url = add_query_arg( 'page', 'table-of-contents', self_admin_url( 'options-general.php' ) ); $setting_link = '' .esc_html__( 'Settings', 'easy-table-of-contents' ) . ' |'; $setting_link .= '' .esc_html__( ' Support', 'easy-table-of-contents' ) . ' |'; $setting_link .= '' .esc_html__( ' Upgrade', 'easy-table-of-contents' ) . ' |'; $setting_link .= '' .esc_html__( ' Website', 'easy-table-of-contents' ) . ''; array_push( $links, $setting_link ); return $links; } /** * Register the scripts used in the admin. * * @access private * @since 1.0 * @static */ public function registerScripts() { $dismissed = explode ( ',', get_user_meta ( wp_get_current_user()->ID, 'dismissed_wp_pointers', true ) ); $do_tour = !in_array ( 'eztoc_subscribe_pointer', $dismissed ); if ( $do_tour ) { wp_enqueue_style ( 'wp-pointer' ); wp_enqueue_script ( 'wp-pointer' ); } $min = defined ( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; wp_register_script( 'cn_toc_admin_script', EZ_TOC_URL . "assets/js/admin{$min}.js", array( 'jquery', 'wp-color-picker' ), ezTOC::VERSION, true ); wp_register_style( 'cn_toc_admin_style', EZ_TOC_URL . "assets/css/admin{$min}.css", array( 'wp-color-picker' ), ezTOC::VERSION ); wp_enqueue_script( 'cn_toc_admin_script' ); $data = array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'eztoc_security_nonce' => wp_create_nonce('eztoc_ajax_check_nonce'), 'is_amp_activated' => (function_exists('ez_toc_is_amp_activated') && ez_toc_is_amp_activated())?1:0 ); $data = apply_filters( 'eztoc_localize_filter', $data, 'eztoc_admin_data' ); wp_localize_script( 'cn_toc_admin_script', 'cn_toc_admin_data', $data ); } /** * Callback to add plugin as a submenu page of the Options page. * * This also adds the action to enqueue the scripts to be loaded on plugin's admin pages only. * * @access private * @since 1.0 * @static */ public function menu() { $page = add_submenu_page( 'options-general.php', esc_html__( 'Table of Contents', 'easy-table-of-contents' ), esc_html__( 'Table of Contents', 'easy-table-of-contents' ), 'manage_options', 'table-of-contents', array( $this, 'page' ) ); add_action( 'admin_print_styles-' . $page, array( $this, 'enqueueScripts' ) ); } /** * Enqueue the scripts. * * @access private * @since 1.0 * @static */ public function enqueueScripts() { wp_enqueue_script( 'cn_toc_admin_script' ); wp_enqueue_style( 'cn_toc_admin_style' ); } /** * Callback to add the action which will register the table of contents post metaboxes. * * Metaboxes will only be registered for the post types per user preferences. * * @access private * @since 1.0 * @static */ public function registerMetaboxes() { if(apply_filters('ez_toc_register_metaboxes_flag', true)){ foreach ( get_post_types() as $type ) { if ( in_array( $type, ezTOC_Option::get( 'enabled_post_types', array() ) ) ) { add_action( "add_meta_boxes_$type", array( $this, 'metabox' ) ); add_action( "save_post_$type", array( $this, 'save' ), 10, 3 ); } } } } /** * Callback to register the table of contents metaboxes. * * @access private * @since 1.0 * @static */ public function metabox() { add_meta_box( 'ez-toc', esc_html__( 'Table of Contents', 'easy-table-of-contents' ), array( $this, 'displayMetabox' ) ); } /** * Callback to render the content of the table of contents metaboxes. * * @access private * @since 1.0 * @static * * @param object $post The post object. * @param $atts */ public function displayMetabox( $post, $atts ) { // Add an nonce field so we can check for it on save. wp_nonce_field( 'ez_toc_save', '_ez_toc_nonce' ); $suppress = get_post_meta( $post->ID, '_ez-toc-disabled', true ) == 1 ? true : false; $insert = get_post_meta( $post->ID, '_ez-toc-insert', true ) == 1 ? true : false; $header_label = get_post_meta( $post->ID, '_ez-toc-header-label', true ); $alignment = get_post_meta( $post->ID, '_ez-toc-alignment', true ); $headings = get_post_meta( $post->ID, '_ez-toc-heading-levels', true ); $exclude = get_post_meta( $post->ID, '_ez-toc-exclude', true ); $altText = get_post_meta( $post->ID, '_ez-toc-alttext', true ); $initial_view = get_post_meta( $post->ID, '_ez-toc-visibility_hide_by_default', true ); $initial_view_device = get_post_meta( $post->ID, '_ez-toc-visibility_hide_by_device', true ); $hide_counter = get_post_meta( $post->ID, '_ez-toc-hide_counter', true ); $position = get_post_meta( $post->ID, '_ez-toc-position-specific', true ); $custom_para_number = get_post_meta( $post->ID, '_ez-toc-s_custom_para_number', true ); $blockqoute_checkbox = get_post_meta( $post->ID, '_ez-toc-s_blockqoute_checkbox', true ); $custom_img_number = get_post_meta( $post->ID, '_ez-toc-s_custom_img_number', true ); if ( ! is_array( $headings ) ) { $headings = array(); } ?>
| 'disabled-toc', 'desc' => esc_html__( 'Disable the automatic insertion of the table of contents.', 'easy-table-of-contents' ), 'default' => $suppress, ), $suppress ); elseif( in_array( get_post_type( $post ), ezTOC_Option::get( 'enabled_post_types', array() ) ) ): ezTOC_Option::checkbox( array( 'id' => 'insert-toc', 'desc' => esc_html__( 'Insert table of contents.', 'easy-table-of-contents' ), 'default' => $insert, ), $insert ); endif; ?> | |
|
'header-label',
'desc' => ' '.__( 'Eg: Contents, Table of Contents, Page Contents', 'easy-table-of-contents' ), 'default' => $header_label, ), $header_label ); ?> |
|
| 'position-specific', 'desc' =>esc_html__( 'Choose where where you want to display the table of contents.', 'easy-table-of-contents' ), 'options' => array( '' =>esc_html__( 'Select Position', 'easy-table-of-contents' ), 'before' =>esc_html__( 'Before first heading (default)', 'easy-table-of-contents' ), 'after' =>esc_html__( 'After first heading', 'easy-table-of-contents' ), 'afterpara' =>esc_html__( 'After first paragraph', 'easy-table-of-contents' ), 'aftercustompara' =>esc_html__( 'After paragraph number', 'easy-table-of-contents' ), 'aftercustomimg' =>esc_html__( 'After Image number', 'easy-table-of-contents' ), 'top' =>esc_html__( 'Top', 'easy-table-of-contents' ), 'bottom' =>esc_html__( 'Bottom', 'easy-table-of-contents' ), ), 'default' => $position, ), $position ); ?> | |
| 's_custom_img_number', 'name' =>esc_html__( 'Select Paragraph', 'easy-table-of-contents' ), 'desc' =>esc_html__( 'Select Image after which ETOC should get display', 'easy-table-of-contents' ), 'type' => 'number', 'size' => 'small', 'default' => $custom_img_number, ), $custom_img_number ); ?> | |
| 's_custom_para_number', 'desc' =>esc_html__( 'Select paragraph after which ETOC should get display', 'easy-table-of-contents' ), 'type' => 'number', 'size' => 'small', 'default' => $custom_para_number, ), $custom_para_number ); ?> | |
| 's_blockqoute_checkbox', 'name' =>esc_html__( 'Exclude Blockqoute', 'easy-table-of-contents' ), 'desc' =>esc_html__( 'Do not consider Paragraphs which are inside Blockqoute.', 'easy-table-of-contents' ), 'default' => false, ), $blockqoute_checkbox ); ?> | |
|
'appearance-desc',
'desc' => ' ' . esc_html__( 'NOTE:', 'easy-table-of-contents' ) . ' ' . '
|
|
| 'toc-alignment', 'options' => array( 'none' =>esc_html__( 'None (Default)', 'easy-table-of-contents' ), 'left' =>esc_html__( 'Left', 'easy-table-of-contents' ), 'right' =>esc_html__( 'Right', 'easy-table-of-contents' ), 'center' =>esc_html__( 'Center', 'easy-table-of-contents' ), ), 'default' => $alignment, ), $alignment ); ?> | |
|
'exclude-desc',
'name' => '',
'desc' => ' ' . esc_html__( 'NOTE:', 'easy-table-of-contents' ) . ' ' . '
|
|
| 'heading-levels', 'desc' => esc_html__( 'Select the heading to consider when generating the table of contents. Deselecting a heading will exclude it.', 'easy-table-of-contents' ), 'options' => array( '1' =>esc_html__( 'Heading 1 (h1)', 'easy-table-of-contents' ), '2' =>esc_html__( 'Heading 2 (h2)', 'easy-table-of-contents' ), '3' =>esc_html__( 'Heading 3 (h3)', 'easy-table-of-contents' ), '4' =>esc_html__( 'Heading 4 (h4)', 'easy-table-of-contents' ), '5' =>esc_html__( 'Heading 5 (h5)', 'easy-table-of-contents' ), '6' =>esc_html__( 'Heading 6 (h6)', 'easy-table-of-contents' ), ), 'default' => array(), ), array_map( 'absint', $headings ) ); ?> | |
| 'visibility_hide_by_default', 'name' =>esc_html__( 'Initial View', 'easy-table-of-contents' ), 'desc' =>esc_html__( 'Initially hide the table of contents.', 'easy-table-of-contents' ), 'default' => false, ), $initial_view ); ?> | |
| 'hide_counter', 'name' =>esc_html__( 'Hide Counter', 'easy-table-of-contents' ), 'desc' =>esc_html__( 'Do not show counters for the table of contents.', 'easy-table-of-contents' ), 'default' => false, ), $hide_counter ); ?> | |
'alttext',
'desc' =>esc_html__( 'Specify alternate table of contents header string. Add the header to be replaced and the alternate header on a single line separated with a pipe |. Put each additional original and alternate header on its own line.', 'easy-table-of-contents' ),
'size' => 'large',
'default' => '',
),
$altText
);
?>
|
|
|
'alttext-desc',
'name' => '',
'desc' => ' ' . esc_html__( 'Examples:', 'easy-table-of-contents' ) . ' ' . '
' . esc_html__( 'Note:', 'easy-table-of-contents' ) . '' . esc_html__( 'This is case sensitive.', 'easy-table-of-contents' ) . ' ', ) ); ?> |
|
'exclude',
'desc' =>esc_html__( 'Specify headings to be excluded from appearing in the table of contents. Separate multiple headings with a pipe |. Use an asterisk * as a wildcard to match other text.', 'easy-table-of-contents' ),
'size' => 'large',
'default' => '',
),
$exclude
);
?>
|
|
|
'exclude-desc',
'name' => '',
'desc' => ' ' . esc_html__( 'Examples:', 'easy-table-of-contents' ) . ' ' . '
|
'.$message.'