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_PLUGIN_DOMAIN ), __( 'Settings', AFFILIATE_PLUGIN_DOMAIN ), 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( __( 'Access denied.', AFFILIATE_PLUGIN_DOMAIN ) ); } $output = ''; $output .= '
'; $output .= '

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

'; $output .= '

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

'; $n = 0; $keywords = get_posts( array( 'numberposts' => -1, 'post_type' => 'affiliate_keyword', 'meta_key' => 'enabled', 'meta_value' => 'yes', 'suppress_filters' => false, 'fields' => 'ids' ) ); if ( $keywords ) { $n = count( $keywords ); } unset( $keywords ); $output .= '

'; $output .= sprintf( _n( 'There is one active keyword.', 'There are active %d keywords.', $n, AFFILIATE_PLUGIN_DOMAIN ), $n ); $output .= '

'; $output .= '

'; $output .= __( 'Keywords can be substituted with links automatically anywhere they appear in the content of the site.', AFFILIATE_PLUGIN_DOMAIN ); $output .= '

'; $output .= '

'; $output .= sprintf( __( 'Keywords are substituted only on post types enabled in the %s.', AFFILIATE_PLUGIN_DOMAIN ), sprintf( '%s', esc_attr( get_admin_url( null, 'admin.php?page=affiliate-settings' ) ), esc_html( __( 'Settings', AFFILIATE_PLUGIN_DOMAIN ) ) ) ); $output .= '

'; $output .= '

'; $output .= __( 'To create a keyword, go to Affiliate > Keywords. Click New Keyword and on the Add New Keyword screen, enter the desired keyword and target URL for the link that should substitute the keyword.', AFFILIATE_PLUGIN_DOMAIN ); $output .= '

'; $output .= '

'; $output .= __( 'Keywords that are enabled will be replaced automatically.', AFFILIATE_PLUGIN_DOMAIN ); $output .= '

'; $output .= '

'; $output .= __( 'Example:', AFFILIATE_PLUGIN_DOMAIN ); $output .= '

'; $output .= '

'; $output .= __( 'Assume you have created and enabled a keyword "Example" that should link to http://www.example.com.', AFFILIATE_PLUGIN_DOMAIN ); $output .= '

'; $output .= '

'; $output .= __( 'The following content ...', AFFILIATE_PLUGIN_DOMAIN ); $output .= '

'; $output .= '
'; $output .= __( 'This is an example of how keyword substitution works.', AFFILIATE_PLUGIN_DOMAIN ); $output .= '
'; $output .= '

'; $output .= __( '... will have the word example replaced by a link:', AFFILIATE_PLUGIN_DOMAIN ); $output .= '

'; $output .= '
'; $output .= __( 'This is an example of how keyword substitution works.', AFFILIATE_PLUGIN_DOMAIN ); $output .= '
'; $output .= '
'; echo $output; } /** * Settings screen. */ public static function affiliate_settings_section() { if ( !current_user_can( self::ADMIN_CAPABILITY ) ) { wp_die( __( 'Access denied.', AFFILIATE_PLUGIN_DOMAIN ) ); } // handle save if ( isset( $_POST['submit'] ) ) { if ( wp_verify_nonce( $_POST['affiliate-settings'], 'save' ) ) { $post_types_option = Affiliate::get_post_types(); $post_types = get_post_types( array( 'public' => true ) ); $selected_post_types = is_array( $_POST['post-type'] ) ? $_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 .= __( 'Settings', AFFILIATE_PLUGIN_DOMAIN ); $output .= '

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

' . __( 'Post Types', AFFILIATE_PLUGIN_DOMAIN ) . '

'; $output .= '

' . __( 'Enable keyword substitution for these post types.', AFFILIATE_PLUGIN_DOMAIN ) . '

'; $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 .= __( 'Keywords are substituted with affiliate links on enabled post types only.', AFFILIATE_PLUGIN_DOMAIN ); $output .= '

      '; $output .= wp_nonce_field( 'save', 'affiliate-settings', true, false ); $output .= sprintf( '', esc_attr( __( 'Save', AFFILIATE_PLUGIN_DOMAIN ) ) ); $output .= '
'; $output .= '
'; $output .= '
'; // render settings echo $output; } /** * Adds plugin links. * * @param array $links * @param array $links with additional links */ public static function admin_settings_link( $links ) { if ( current_user_can( self::ADMIN_CAPABILITY ) ) { $links = array( '' . __( 'Affiliate', AFFILIATE_PLUGIN_DOMAIN ) . '', '' . __( 'Settings', AFFILIATE_PLUGIN_DOMAIN ) . '' ) + $links; } return $links; } } add_action( 'init', array( 'Affiliate_Admin', 'init' ) );