Changeset 1295326
- Timestamp:
- 11/26/2015 11:56:25 PM (3 years ago)
- Location:
- envira-tamer
- Files:
-
- 5 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
envira-tamer/trunk/admin/settings-page.php
r1011854 r1295326 2 2 defined( 'ABSPATH' ) OR exit; 3 3 4 /* 5 * Setup the settings page for Envira Tamer. 6 * 7 * @package PackageName 8 * @author Mike Selander <[email protected]> 9 * @since 1.0.0 10 */ 4 11 class EnviraTamerSettingsPage { 12 13 /** 14 * dir 15 * Main directory path. 16 * 17 * @var string 18 * @access private 19 */ 5 20 private $dir; 21 22 /** 23 * file 24 * Main file path. 25 * 26 * @var string 27 * @access private 28 */ 6 29 private $file; 7 private $assets_dir; 8 private $assets_url; 30 31 /** 32 * settings_base 33 * Prefix for the settings. 34 * 35 * @var string 36 * @access private 37 */ 9 38 private $settings_base; 39 40 /** 41 * settings 42 * Array of the settings. 43 * 44 * @var array 45 * @access private 46 */ 10 47 private $settings; 11 48 49 50 /** 51 * Constructor function. 52 * 53 * @see add_action, add_filter 54 */ 12 55 public function __construct( $file ) { 13 $this->file = $file; 14 $this->dir = dirname( $this->file ); 15 $this->assets_dir = trailingslashit( $this->dir ) . 'assets'; 16 $this->assets_url = esc_url( trailingslashit( plugins_url( '/assets/', $this->file ) ) ); 56 57 $this->file = $file; 58 $this->dir = dirname( $this->file ); 17 59 $this->settings_base = 'et_'; 18 60 … … 21 63 add_action( 'admin_menu', array( $this, 'add_menu_item' ) ); 22 64 add_filter( 'plugin_action_links_' . plugin_basename( $this->file ) , array( $this, 'add_settings_link' ) ); 65 23 66 } 24 67 25 68 /** 26 69 * Initialise settings 27 * @return void28 70 */ 29 71 public function init() { 72 30 73 $this->settings = $this->settings_fields(); 31 } 32 33 /** 34 * Add settings page to admin menu 35 * @return void 74 75 } 76 77 78 /** 79 * Add settings page to admin menu. 80 * 81 * @see add_submenu_page 36 82 */ 37 83 public function add_menu_item() { 84 38 85 add_submenu_page( 39 86 'edit.php?post_type=envira', … … 44 91 array( $this, 'settings_page' ) 45 92 ); 46 } 47 48 /** 49 * Add settings link to plugin list table 93 94 } 95 96 97 /** 98 * Add settings link to plugin list table. 99 * 50 100 * @param array $links Existing links 51 * @return array 101 * @return array Modified links 52 102 */ 53 103 public function add_settings_link( $links ) { 104 54 105 $settings_link = '<a href="edit.php?post_type=envira&page=envira_tamer">' . __( 'Settings', 'envira_tamer' ) . '</a>'; 55 106 array_push( $links, $settings_link ); 107 56 108 return $links; 57 } 58 59 /** 60 * Build settings fields 109 110 } 111 112 113 /** 114 * Build settings fields. 115 * 61 116 * @return array Fields to be displayed on settings page 62 117 */ … … 94 149 95 150 return $settings; 96 } 97 98 /** 99 * Register plugin settings 100 * @return void 151 152 } 153 154 155 /** 156 * Register plugin settings. 157 * 158 * 101 159 */ 102 160 public function register_settings() { 103 if( is_array( $this->settings ) ) { 104 foreach( $this->settings as $section => $data ) { 105 106 // Add section to page 107 add_settings_section( $section, $data['title'], array( $this, 'settings_section' ), 'envira_tamer' ); 108 109 foreach( $data['fields'] as $field ) { 110 111 // Validation callback for field 112 $validation = ''; 113 if( isset( $field['callback'] ) ) { 114 $validation = $field['callback']; 115 } 116 117 // Register field 118 $option_name = $this->settings_base . $field['id']; 119 register_setting( 'envira_tamer', $option_name, $validation ); 120 121 // Add field to page 122 add_settings_field( $field['id'], $field['label'], array( $this, 'display_field' ), 'envira_tamer', $section, array( 'field' => $field ) ); 161 162 if ( !is_array( $this->settings ) ) { 163 return; 164 } 165 166 foreach ( $this->settings as $section => $data ) { 167 168 // Add section to page 169 add_settings_section( $section, $data['title'], '', 'envira_tamer' ); 170 171 foreach( $data['fields'] as $field ) { 172 173 // Validation callback for field 174 $validation = ''; 175 if( isset( $field['callback'] ) ) { 176 $validation = $field['callback']; 123 177 } 124 } 125 } 126 } 127 128 public function settings_section( $section ) { 129 $html = '<p> ' . $this->settings[ $section['id'] ]['description'] . '</p>' . "\n"; 130 echo $html; 131 } 132 133 /** 134 * Generate HTML for displaying fields 178 179 // Register field 180 $option_name = $this->settings_base . $field['id']; 181 register_setting( 'envira_tamer', $option_name, $validation ); 182 183 // Add field to page 184 add_settings_field( $field['id'], $field['label'], array( $this, 'display_field' ), 'envira_tamer', $section, array( 'field' => $field ) ); 185 } // end foreach ['fields'] 186 187 } // end foreach $settings 188 189 } 190 191 192 /** 193 * Generate HTML for displaying fields. 194 * 135 195 * @param array $args Field data 136 * @return void137 196 */ 138 197 public function display_field( $args ) { … … 140 199 $field = $args['field']; 141 200 142 $html = '';201 $html = $data = ''; 143 202 144 203 $option_name = $this->settings_base . $field['id']; 145 204 $option = get_option( $option_name ); 146 205 147 $data = '';206 // 148 207 if( isset( $field['default'] ) ) { 149 208 $data = $field['default']; … … 153 212 } 154 213 155 switch( $field['type'] ) { 156 157 case 'checkbox_multi': 158 foreach( $field['options'] as $k => $v ) { 159 $checked = false; 160 if( in_array( $k, $data ) ) { 161 $checked = true; 162 } 163 $html .= '<label for="' . esc_attr( $field['id'] . '_' . $k ) . '"><input type="checkbox" ' . checked( $checked, true, false ) . ' name="' . esc_attr( $option_name ) . '[]" value="' . esc_attr( $k ) . '" id="' . esc_attr( $field['id'] . '_' . $k ) . '" /> ' . $v . '</label><br>'; 164 } 165 $html .= '<br/><span class="description">' . $field['description'] . '</span>'; 166 break; 167 168 } 214 // Loop through the post type options 215 foreach( $field['options'] as $k => $v ) { 216 217 // Check our field if need be. 218 $checked = false; 219 if( in_array( $k, $data ) ) { 220 $checked = true; 221 } 222 223 // Main output 224 $html .= '<label for="' . esc_attr( $field['id'] . '_' . $k ) . '"><input type="checkbox" ' . checked( $checked, true, false ) . ' name="' . esc_attr( $option_name ) . '[]" value="' . esc_attr( $k ) . '" id="' . esc_attr( $field['id'] . '_' . $k ) . '" /> ' . $v . '</label><br>'; 225 226 } 227 228 $html .= '<br/><span class="description">' . $field['description'] . '</span>'; 169 229 170 230 echo $html; 171 } 231 232 } 233 172 234 173 235 /** 174 236 * Validate individual settings field 237 * 175 238 * @param string $data Inputted value 176 239 * @return string Validated value … … 178 241 public function validate_field( $data ) { 179 242 180 if ( $data && strlen( $data ) > 0 && $data != '' ) {243 if ( $data && strlen( $data ) > 0 && $data != '' ) { 181 244 $data = urlencode( strtolower( str_replace( ' ' , '-' , $data ) ) ); 182 245 } 183 246 184 247 return $data; 185 } 186 187 /** 188 * Load settings page content 189 * @return void 248 249 } 250 251 252 /** 253 * Print the page content for the settings section of Envira Tamer. 254 * 255 * @see settings_fields, do_settings_sections 190 256 */ 191 257 public function settings_page() { … … 200 266 // Get settings fields 201 267 ob_start(); 202 settings_fields( 'envira_tamer' ); 203 do_settings_sections( 'envira_tamer' ); 268 269 settings_fields( 'envira_tamer' ); 270 do_settings_sections( 'envira_tamer' ); 271 204 272 $html .= ob_get_clean(); 205 273 -
envira-tamer/trunk/envira-tamer.php
r1011854 r1295326 5 5 Description: Control which post types Envira Gallery meta box field shows up on 6 6 Author: Mike Selander 7 Version: 1.0 7 Version: 1.0.1 8 8 Author URI: http://www.mikeselander.com/ 9 License: GPLv2 or later 9 10 */ 10 11 11 // Load the settings page if we're in the admin section 12 /* 13 * Load the settings page if we're in the admin section 14 */ 12 15 if ( is_admin() ){ 13 16 require_once( 'admin/settings-page.php' ); … … 15 18 } 16 19 20 /* 21 * Apply our settings to Envira to restrict the post types. 22 * 23 * @see envira_gallery_skipped_posttypes, get_option 24 */ 17 25 add_filter( 'envira_gallery_skipped_posttypes', 'restrict_envira_post_types' ); 18 26 function restrict_envira_post_types( $rejects ){ -
envira-tamer/trunk/readme.txt
r1011854 r1295326 4 4 Tags: envira, gallery, custom post type, cpt, envira gallery, retrict 5 5 Requires at least: 3.8 6 Tested up to: 4. 07 Stable tag: 1.0 6 Tested up to: 4.4 7 Stable tag: 1.0.1 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 12 12 13 13 == Description == 14 15 This plugin appears to no longer be needed, but I am cleaning it up and maintaining it for those on legacy versions of Envira Gallery. 14 16 15 17 Envira Gallery is an amazing gallery plugin, however it displays its metabox on every post type on your site. This is unnecessary and distracting for you and your clients. This plugin gives you an easy to use settings page that allows you to quickly change the post types that the metabox shows on. … … 27 29 == Upgrade Notice == 28 30 31 = 1.0.1 = 32 Cleaning up, commenting, and getting rid of unnecessary methods 33 29 34 = 1.0.0 = 30 35 Initial Release
Note: See TracChangeset
for help on using the changeset viewer.