labels->name, $affiliate_keyword_cpt->labels->all_items, $affiliate_keyword_cpt->cap->edit_posts, "edit.php?post_type=affiliate_keyword" ); // remove_submenu_page( 'affiliate-admin', 'affiliate-admin' ); // @todo Links menu item // $affiliate_link_cpt = get_post_type_object( 'affiliate_link' ); // add_submenu_page( // 'affiliate-admin', // $affiliate_link_cpt->labels->name, // $affiliate_link_cpt->labels->all_items, // $affiliate_link_cpt->cap->edit_posts, // "edit.php?post_type=affiliate_link" // ); // Settings menu item $page = add_submenu_page( 'affiliate-admin', __( 'Settings', 'affiliate' ), __( 'Settings', 'affiliate' ), self::ADMIN_CAPABILITY, 'affiliate-settings', array( __CLASS__, 'affiliate_settings_section' ) ); add_action( 'admin_print_styles-' . $page, array( __CLASS__, 'admin_print_styles' ) ); } /** * Affiliate administration screen. */ public static function affiliate_admin_section() { if ( !current_user_can( self::ADMIN_CAPABILITY ) ) { wp_die( esc_html__( 'Access denied.', 'affiliate' ) ); } $output = ''; $output .= '
'; $output .= '

'; $output .= __( 'Affiliate', 'affiliate' ); $output .= '

'; $output .= '

'; $output .= __( 'Keywords', 'affiliate' ); $output .= '

'; $n = 0; $keywords = get_posts( array( 'numberposts' => -1, 'post_type' => 'affiliate_keyword', 'meta_key' => 'enabled', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key 'meta_value' => 'yes', // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value 'suppress_filters' => false, 'fields' => 'ids' ) ); if ( $keywords ) { $n = count( $keywords ); } unset( $keywords ); $output .= '
'; $output .= '

'; $output .= sprintf( esc_html( /* translators: amount of active keywords */ _n( 'There is %d active keyword.', 'There are %d active keywords.', $n, 'affiliate' ) ), $n, $n ); $output .= '

'; $output .= '
'; $output .= '

'; $output .= esc_html__( 'Keywords can be automatically replaced with links.', 'affiliate' ); $output .= ' '; $output .= esc_html__( 'Wherever those keywords appear in the page content, the system can replace them.', 'affiliate' ); $output .= ' '; $output .= esc_html__( 'You must enable keyword substitution for the desired post types.', 'affiliate' ); $output .= ' '; $output .= sprintf( /* translators: settings link */ esc_html__( 'Keywords are substituted only on post types enabled in the %s.', 'affiliate' ), sprintf( '%s', esc_attr( get_admin_url( null, 'admin.php?page=affiliate-settings' ) ), esc_html__( 'Settings', 'affiliate' ) ) ); $output .= '

'; $output .= '

'; $output .= sprintf( /* translators: documentation link */ esc_html__( 'Visit the %s pages for detailed information.', 'affiliate' ), sprintf( '%s', esc_html__( 'Documentation', 'affiliate' ) ) ); $output .= '

'; $output .= '
'; echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Settings screen. */ public static function affiliate_settings_section() { if ( !current_user_can( self::ADMIN_CAPABILITY ) ) { wp_die( esc_html__( 'Access denied.', 'affiliate' ) ); } // handle save if ( isset( $_POST['submit'] ) ) { if ( isset( $_POST['affiliate-settings'] ) && wp_verify_nonce( sanitize_key( wp_unslash( $_POST['affiliate-settings'] ) ), 'save' ) ) { $post_types_option = Affiliate::get_post_types(); $post_types = get_post_types( array( 'public' => true ) ); $selected_post_types = isset( $_POST['post-type'] ) && is_array( $_POST['post-type'] ) ? array_map( 'sanitize_key', wp_unslash( $_POST['post-type'] ) ) : array(); foreach( $post_types as $post_type ) { $post_types_option[$post_type] = in_array( $post_type, $selected_post_types ); } Affiliate::set_post_types( $post_types_option ); } } // build settings $output = ''; $output .= '
'; $output .= '

'; $output .= esc_html__( 'Settings', 'affiliate' ); $output .= '

'; $output .= '
'; $output .= '
'; $output .= '

' . esc_html__( 'Post Types', 'affiliate' ) . '

'; $output .= '

' . esc_html__( 'Enable keyword substitution for these post types.', 'affiliate' ) . '

'; $post_types_option = Affiliate::get_post_types(); $post_types = get_post_types( array( 'public' => true ) ); $output .= '
    '; foreach( $post_types as $post_type ) { $post_type_object = get_post_type_object( $post_type ); $output .= '
  • '; $output .= ''; $output .= '
  • '; } $output .= '
      '; $output .= '

      '; $output .= esc_html__( 'Keywords are substituted with affiliate links on enabled post types only.', 'affiliate' ); $output .= '

      '; $output .= wp_nonce_field( 'save', 'affiliate-settings', true, false ); $output .= sprintf( '', esc_attr__( 'Save', 'affiliate' ) ); $output .= '
'; $output .= '
'; $output .= '
'; // render settings echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped } /** * Adds plugin links. * * @param array $links * @param array $links with additional links * * @return array of links */ public static function admin_settings_link( $links ) { $add = array(); if ( current_user_can( self::ADMIN_CAPABILITY ) ) { $add[] = '' . esc_html__( 'Affiliate', 'affiliate' ) . ''; } $add[] = '' . esc_html__( 'Documentation', 'affiliate' ) . ''; $add[] = '' . esc_html__( 'Shop', 'affiliate' ) . ''; if ( current_user_can( self::ADMIN_CAPABILITY ) ) { $add[] = '' . esc_html__( 'Settings', 'affiliate' ) . ''; } $links = array_merge( $add, $links ); return $links; } } add_action( 'init', array( 'Affiliate_Admin', 'init' ) );