Changeset 1255768
- Timestamp:
- 09/29/2015 12:34:20 PM (9 years ago)
- Location:
- admin-form-framework/trunk
- Files:
-
- 10 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
admin-form-framework/trunk/aff.js
r834287 r1255768 204 204 }); 205 205 206 207 208 209 210 211 212 213 206 214 }); 207 215 -
admin-form-framework/trunk/class-aff.php
r839188 r1255768 4 4 * Plugin URI: http://dreamproduction.com/wordpress/admin-form-framework 5 5 * Description: Small framework for building Admin pages with forms. This plugin provides a wrapper for the WordPress Settings API that is a much easier, faster and extensible way of building your settings forms. 6 * Version: 1. 0.16 * Version: 1. 7 7 * Author: Dan Stefancu 8 8 * Author URI: http://stefancu.ro/ … … 26 26 var $menu_hook = 'admin_menu'; 27 27 var $button_text = null; 28 29 30 31 32 33 34 28 35 29 36 private $hook_suffix; … … 38 45 public function init() { 39 46 40 $this->saved_options = get_option( $this->options_name ); 47 if ( class_exists( 'Sitepress' ) && $this->multilingual_options ) { 48 global $sitepress; 49 50 if ( $sitepress->get_default_language() != $sitepress->get_current_language() ) { 51 $this->options_name .= '-' . $sitepress->get_current_language(); 52 } 53 } 54 55 if ( empty($this->saved_options) ) { 56 if( $this->menu_hook == "network_admin_menu" ) { 57 $this->saved_options = get_site_option( $this->options_name ); 58 add_action('update_wpmu_options', array( $this, 'update_site_options') ); 59 } else { 60 $this->saved_options = get_option( $this->options_name ); 61 } 62 } 41 63 42 64 add_action( $this->menu_hook, array( $this, 'add_page' ), 11 ); 43 65 66 44 67 add_action( 'admin_init', array( $this, 'sections_init' ), 11 ); 45 68 add_action( 'admin_init', array( $this, 'options_init' ), 12 ); … … 82 105 $this->page_slug // page slug 83 106 ); 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 84 145 } 85 146 } … … 203 264 */ 204 265 function display_description( $text = '' ) { 205 if ( $text ) { 206 ?> 207 <p class="description"><?php echo $text; ?></p> 208 <?php 209 } 266 if ( ! $text ) { 267 return; 268 } 269 include( 'views/description.php' ); 210 270 } 211 271 … … 216 276 */ 217 277 function display_textarea( $field_name, $field_value, $extra = array() ) { 218 ?> 219 <textarea class="large-text" name="<?php echo $field_name; ?>"><?php echo esc_textarea( $field_value ); ?></textarea> 220 <?php 278 include( 'views/textarea.php' ); 221 279 } 222 280 … … 227 285 */ 228 286 function display_checkbox( $field_name, $field_value, $extra = array() ) { 229 ?> 230 <input type="checkbox" name="<?php echo $field_name; ?>" value="1" <?php echo checked( 1, $field_value ); ?> /> 231 <?php 287 include( 'views/checkbox.php' ); 232 288 } 233 289 … … 238 294 */ 239 295 function display_text( $field_name, $field_value, $extra = array() ) { 240 ?> 241 <input type="text" class="regular-text" name="<?php echo $field_name; ?>" value="<?php echo esc_attr( $field_value ); ?>"/> 242 <?php 296 include ( 'views/text.php' ); 243 297 } 244 298 … … 249 303 */ 250 304 function display_select( $field_name, $field_value, $extra = array() ) { 251 if ( ! isset( $extra['options'] ) ) {305 if ( !isset( $extra['options'] ) ) { 252 306 return; 253 307 } 254 ?> 255 <select name="<?php echo $field_name; ?>"> 256 <?php foreach ( $extra['options'] as $value => $title ): ?> 257 <option value="<?php echo $value; ?>" <?php selected( $field_value, $value ); ?>><?php echo $title; ?></option> 258 <?php endforeach; ?> 259 </select> 260 <?php 308 include( 'views/select.php' ); 261 309 } 262 310 … … 270 318 return; 271 319 272 foreach ( $extra['options'] as $value => $title ) { ?> 273 <label><input type="radio" name="<?php echo $field_name; ?>" value="<?php echo $value; ?>" <?php checked( $field_value, $value ); ?>/> 274 <?php echo $title; ?> 275 </label><br/> 276 <?php 277 } 320 include( 'views/radio.php' ); 278 321 } 279 322 … … 284 327 */ 285 328 function display_image( $field_name, $field_value, $extra = array() ) { 286 $button_name = $field_name . '_button';287 $type = 'image';288 $class = isset( $extra['class'] ) ? $extra['class'] : 'options-page-image'; 289 if ( $field_value ) {290 $attachment = get_post( $field_value );291 $filename = basename( $attachment->guid );292 $icon_src = wp_get_attachment_image_src( $attachment->ID, 'medium' );293 $icon_src = array_values( $icon_src );294 $icon_src = array_shift( $icon_src );295 $uploader_div = 'hidden';296 $display_div = '';297 } else { 298 $uploader_div = '';299 $display_div = 'hidden';300 $filename = '';301 $icon_src = wp_mime_type_icon( $type );302 }303 304 ?>305 306 <div class="<?php echo $class; ?> dp-field" data-type="<?php echo $type; ?>"> 307 <input type="hidden" class="file-value" name="<?php echo $field_name; ?>" id="<?php echo $field_name; ?>" value="<?php echo esc_attr( $field_value ); ?>"/>308 309 <div class="file-missing <?php echo $uploader_div; ?>">310 <span><?php _e( 'No file selected.', 'dp' ); ?></span>311 <button class="button file-add" name="<?php echo $button_name; ?>" id="<?php echo $button_name; ?>"><?php _e( 'Add file', 'dp' ) ?></button>312 </div>313 <div class="file-exists clearfix <?php echo $display_div; ?>">314 <img class="file-icon" src="<?php echo $icon_src; ?>"/> 315 <br/>316 <span class="file-name hidden"><?php echo $filename; ?></span>317 <a class="file-remove button" href="#"><?php _e( 'Remove', 'dp' ); ?></a>318 </div>319 </div>320 <?php 321 }322 329 ; 330 331 332 333 334 335 336 337 338 ; 339 340 341 342 343 344 345 346 function display_wysiwyg( $field_name, $field_value, $extra = array() ) { 347 348 } 349 350 351 * Returns all used field types 352 353 354 355 356 357 358 359 360 361 362 363 364 365 } 323 366 /** 324 367 * Display the options page 325 368 */ 326 369 function render_page() { 327 global $wp_version; 328 ?> 329 <div class="wrap"> 330 <?php if ( version_compare( $wp_version, '3.8', '<' ) ) { screen_icon(); } ?> 331 332 <h2><?php echo $this->title; ?></h2> 333 334 <form method="post" action="<?php echo admin_url( 'options.php' ); ?>"> 335 <?php 336 settings_fields( $this->options_name ); 337 do_settings_sections( $this->page_slug ); 338 if ( $this->button_text !== false ) submit_button( $this->button_text ); 339 ?> 340 </form> 341 </div><!-- .wrap --> 342 <?php 370 include( 'views/options-page.php' ); 371 } 372 373 /** 374 * Update site options in case the form is a network admin menu 375 * @return void 376 */ 377 function update_site_options() { 378 379 if ( isset( $_POST[ $this->options_name ] ) ) { 380 $value = stripslashes_deep( $_POST[ $this->options_name ] ); 381 update_site_option( $this->options_name, $value ); 382 383 if( isset( $_POST['_wp_http_referer'] ) ) { 384 wp_redirect( add_query_arg( 'updated', 'true', $_POST['_wp_http_referer'] ) ); 385 exit(); 386 } 387 } 343 388 } 344 389 … … 365 410 return home_url( trailingslashit( $path_from_root ) . $file ); 366 411 } 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 367 430 } -
admin-form-framework/trunk/readme.txt
r839188 r1255768 2 2 Contributors: de-ce, dream-production 3 3 Tags: development, settings, options, custom, admin 4 Requires at least: 3. 55 Tested up to: 3.86 Stable tag: 1.0.14 Requires at least: 3. 5 Tested up to: 6 Stable tag: 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 71 71 == Changelog == 72 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 73 97 = 1.0.1 = 74 98 * Fixed example and readme.
Note: See TracChangeset
for help on using the changeset viewer.