Changeset 800
- Timestamp:
- 08/19/2014 05:34:26 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/handbook.php
r776 r800 38 38 39 39 public $post_type = ''; 40 public $setting_name = ''; 40 41 41 42 protected $label = ''; … … 57 58 } 58 59 60 /** 61 * Returns the handbook name. 62 * 63 * If one isn't set via settings, one is generated. 64 * 65 * @param string $post_type Optional. Handbook post type. 66 * @param bool $raw Optional. Return only explicitly set name without attempting to generate default name? 67 * @return string 68 */ 69 static function get_name( $post_type = 'handbook', $raw = false ) { 70 // Prefer explicitly configured handbook name. 71 $name = get_option( $post_type . '_name' ); 72 73 // If handbook name isn't set, try root relative site path. 74 if ( ! $raw && empty( $name ) ) { 75 if ( is_multisite() ) { 76 $name = trim( get_blog_details()->path, '/' ); 77 } else { 78 $name = trim( parse_url( get_option( 'home' ), PHP_URL_PATH ), '/' ); 79 } 80 81 // If no name defined yet, try handbook post type if not standard. 82 if ( empty( $name ) && ( 'handbook' != $post_type ) ) { 83 $name = ucfirst( substr( $post_type, 0, -9 ) ); 84 } 85 86 $name .= ' Handbook'; 87 } 88 89 return trim( $name ); 90 } 91 59 92 function __construct( $type ) { 60 93 if ( 'handbook' != $type ) { … … 65 98 66 99 $this->label = ucwords( str_replace( array( '-', '_' ), ' ', $this->post_type ) ); 100 101 $this->setting_name = $this->post_type . '_name'; 67 102 68 103 add_filter( 'user_has_cap', array( $this, 'grant_handbook_caps' ) ); … … 74 109 add_action( 'wporg_email_changes_for_post_types', array( $this, 'wporg_email_changes_for_post_types' ) ); 75 110 add_action( 'p2_action_links', array( $this, 'disable_p2_resolved_posts_action_links' ) ); 111 add_action( 'admin_init', array( $this, 'add_name_setting' ) ); 112 } 113 114 function add_name_setting() { 115 register_setting( 'general', $this->setting_name, 'esc_attr' ); 116 117 $label = ( 'handbook' == $this->post_type ) ? 118 __( 'Handbook name', 'wporg' ) : 119 sprintf( __( 'Handbook name (%s)', 'wporg' ), substr( $this->post_type, 0, -9 ) ); 120 121 add_settings_field( 122 $this->setting_name, 123 '<label for="' . esc_attr( $this->setting_name ) . '">' . $label . '</label>', 124 array( $this, 'name_setting_html' ), 125 'general' 126 ); 127 } 128 129 function name_setting_html() { 130 $value = get_option( $this->setting_name, '' ); 131 echo '<input type="text" id="' . esc_attr( $this->setting_name ) . '" name="' . esc_attr( $this->setting_name ) . '" value="' . esc_attr( $value ) . '" class="regular-text ltr" />'; 76 132 } 77 133
Note: See TracChangeset
for help on using the changeset viewer.