post_type ) { wp_enqueue_script( 'wbcr-inp-admin-scripts', WINP_PLUGIN_URL . '/admin/assets/js/scripts.js', [ 'jquery', 'jquery-ui-tooltip', ], WINP_PLUGIN_VERSION ); } } /** * Asset scripts for the tinymce editor * * @param string $hook */ function wbcr_inp_enqueue_tinymce_assets( $hook ) { $pages = [ 'post.php', 'post-new.php', 'widgets.php', ]; if ( ! in_array( $hook, $pages ) || ! current_user_can( 'edit_posts' ) ) { return; } wp_enqueue_script( 'wbcr-inp-tinymce-button-widget', WINP_PLUGIN_URL . '/admin/assets/js/tinymce4.4.js', [ 'jquery' ], WINP_PLUGIN_VERSION, true ); } add_action( 'admin_enqueue_scripts', 'wbcr_inp_enqueue_tinymce_assets' ); add_action( 'admin_enqueue_scripts', 'wbcr_inp_enqueue_scripts' ); /** * Adds js variable required for shortcodes. * * @since 1.1.0 * @see before_wp_tiny_mce */ function wbcr_inp_tinymce_data( $hook ) { if ( ! current_user_can( 'edit_posts' ) ) { return; } // styles for the plugin shorcodes $shortcode_icon = WINP_PLUGIN_URL . '/admin/assets/img/shortcode-icon5.png'; $shortcode_title = __( 'Woody Code Snippets', 'insert-php' ); $result = WINP_Helper::get_shortcode_data( true ); $shortcode_snippets_json = json_encode( $result ); ?> $menu Menu items. * * @return array */ function wbcr_inp_reorder_submenu_items( $menu ) { global $submenu; if ( ! isset( $submenu[ 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE ] ) ) { return $menu; } $snippet_submenu = $submenu[ 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE ]; $new_item_page = null; $new_item_key = null; foreach ( $snippet_submenu as $key => $item ) { if ( strpos( $item[2], 'new-item-' ) !== false ) { $new_item_page = $item; $new_item_key = $key; break; } } if ( null !== $new_item_page ) { unset( $submenu[ 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE ][ $new_item_key ] ); $submenu[ 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE ][6] = $new_item_page; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited ksort( $submenu[ 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE ] ); } return $menu; } add_filter( 'admin_menu', 'wbcr_inp_reorder_submenu_items', 999 ); /** * If the user tried to get access to the default 'new item', * redirects forcibly to our page 'new item'. * * @see current_screen */ function wbcr_inp_redirect_to_new_item() { $screen = get_current_screen(); if ( empty( $screen ) ) { return; } if ( 'add' !== $screen->action || 'post' !== $screen->base || WINP_SNIPPETS_POST_TYPE !== $screen->post_type ) { return; } $winp_item = WINP_HTTP::get( 'winp_item', null ); if ( ! is_null( $winp_item ) ) { return; } $url = admin_url( 'edit.php?post_type=' . WINP_SNIPPETS_POST_TYPE . '&page=winp-new-item' ); wp_safe_redirect( $url ); exit; } add_action( 'current_screen', 'wbcr_inp_redirect_to_new_item' );