Changeset 500696
- Timestamp:
- 02/05/2012 06:57:58 PM (14 years ago)
- Location:
- diy/trunk
- Files:
-
- 3 edited
-
diy.php (modified) (93 diffs)
-
diytests.php (modified) (17 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
diy/trunk/diy.php
r498186 r500696 42 42 * The Abstract Diy Class 43 43 * 44 * @since 0. 144 * @since 0.0.1 45 45 * @access public 46 46 */ … … 100 100 * @var array Set to true to remove sidebar metaboxes on the options page 101 101 */ 102 protected $ is_generic = false;102 protected $generic = false; 103 103 104 104 /** … … 132 132 protected $diy_url = ''; 133 133 134 /** 135 * @var string The plugin page 136 */ 137 protected $page = ''; 138 139 /** 140 * @var array metaboxes 141 */ 142 protected $metaboxes = array(); 143 144 /** 145 * @var array fields 146 */ 147 protected $fields = array(); 148 149 /** 150 * @var array version 151 */ 152 protected $version = '0.0.1'; 153 154 /** 155 * @var array icon file 156 */ 157 protected $icon = ''; 158 159 /** 160 * @var array Store an array of WP_Query arguments use by suggest field widgets during an ajax request (indexed by [group][field]) 161 */ 162 protected $suggest_queries = array(); 163 164 /** 165 * @var array The defaults applied to all new metaboxes 166 */ 167 protected $metabox_defaults = array ( 168 "context" => "normal", 169 "post_callback" => "post_metabox_builder", 170 "option_callback" => "diy_option_field_builder", 171 "description" => "", 172 "footer" => "", 173 "sortable" => false 174 ); 175 176 /** 177 * @var array The defaults applied to an individual field 178 */ 179 protected $field_defaults = array ( 180 "tooltip" => "", 181 "label_width" => "", 182 "label_style" => "", 183 "title" => "", 184 "description" => "", 185 "width" => "", 186 "height" => "", 187 "multiple" => "", 188 "suffix" => "", 189 "prefix"=>"", 190 "function"=>"", 191 "placeholder"=>"", 192 "required"=>"", 193 "preview" => false, 194 "map" => "", 195 "default" => "", 196 "wp_query" => "", 197 "expanded" => false 198 199 ); 200 201 /** 202 * @var array The defaults applied to a group of fields 203 */ 204 protected $field_group_defaults = array ( 205 "description" => "", 206 "sortable" => false, 207 "style" => "", 208 ); 209 210 /** 211 * Constructor 212 * 213 * @since 0.0.1 214 * @param string $file The filename of the plugin extending this class 215 * @access public 216 * @return void 217 */ 218 function __construct($file = __FILE__) { 219 // Save the filename of the child plugin 220 $this->filename = plugin_basename($file); 221 222 // Initialise the plugin if the method has been defined in the extended class 223 if ( is_callable( array($this, 'init') ) ) { 224 $this->init(); 225 } 226 227 // @todo Sanity check for properties and field declarations 228 229 // Start the plugin 230 $this->diy_start(); 231 232 // Call the child plugins start method 233 if ( is_callable( array($this, 'start') ) ) { 234 $this->start(); 235 } 236 } // function 134 237 135 238 /** 136 239 * This starts the process of defining the plugin 137 * @return void 240 * @return void 138 241 */ 139 242 public function diy_start() { … … 144 247 } 145 248 146 // generate the options_group var name249 // generate the options_group variable name from the slug 147 250 if ($this->options_group == '') { 148 251 $this->options_group = $this->slug; … … 163 266 $this->diy_url = str_replace(ABSPATH,trailingslashit(get_option( 'siteurl' )),$this->diy_path); 164 267 165 // Register the child plugins fields 166 add_action('admin_init', array($this,'diy_fields')); 167 168 // Register the child plugins metaboxes 169 add_action('admin_init', array($this,'diy_metaboxes')); 170 171 // Save the custom post fields with the post data 172 add_action('save_post', array(&$this,'diy_save_post')); 173 174 // Register the scripts and styles needed for metaboxes and fields 175 add_action('admin_init', array(&$this,'diy_scripts_and_styles') ); 176 177 // Add the plugins options page unless the Diy Class is being used just for metaboxes 178 if ($this->usage != 'meta') { 268 // Save some effort if its an ajax request 269 if (!defined('DOING_AJAX') || !DOING_AJAX) { 270 // Register the child plugins fields 271 add_action('admin_init', array($this,'diy_fields')); 272 273 // Register the child plugins metaboxes 274 add_action('admin_init', array($this,'diy_metaboxes')); 275 276 // Force the plugin options page to have two columns 277 add_filter('screen_layout_columns', array(&$this, 'diy_settings_page_columns'), 10, 2); 278 279 // Save the custom post fields with the post data 280 add_action('save_post', array(&$this,'diy_save_post')); 281 282 // Register the scripts and styles needed for metaboxes and fields 283 add_action('admin_init', array(&$this,'diy_scripts_and_styles') ); 284 285 // Add the plugins options page unless the Diy Class is being used just for metaboxes 286 if ($this->usage != 'meta') { 179 287 // Add the plugins options page 180 288 add_action( 'admin_menu', array($this,'diy_add_options_page') ); 181 } 182 183 // Force the plugin options page to have two columns 184 add_filter('screen_layout_columns', array(&$this, 'diy_options_page_columns'), 10, 2); 185 186 // Add the predefined metaboxes to the plugin options page as long as is_generic isnt true 187 if ($this->is_generic == false) { 289 } 290 291 // Add the predefined metaboxes to the plugin options page as long as generic isnt true 292 if ($this->generic == false) { 188 293 add_action('admin_init', array(&$this,'diy_add_predefined_metaboxes') ); 294 } 189 295 } 190 296 191 297 // Setup the ajax callback for autocomplete widget 192 298 add_action('wp_ajax_suggest_action', array(&$this,'diy_suggest_posts_callback')); 193 // add_action('wp_ajax_suggest_action', array(&$this,'diy_suggest_users_callback')); 194 299 // add_action('wp_ajax_suggest_action', array(&$this,'diy_suggest_users_callback')); 300 add_filter( 'posts_where', array(&$this,'diy_modify_posts_where'), 10, 2 ); 301 302 195 303 // Setup some query vars to serve javascript and css via a url 196 304 add_action( 'template_redirect', array( &$this, 'diy_script_server' )); … … 198 306 199 307 } // end function 200 201 202 /** 308 309 /** 203 310 * Return a link to the admin icon 204 311 * @param string $hook Current page hook … … 207 314 function diy_settings_page_icon( $hook ) { 208 315 if ($hook == $this->hook) 209 return plugin_dir_url( __FILE__ ).$this->icon;316 return plugin_dir_url( __FILE__ ).$this->icon; 210 317 return $hook; 211 318 } 212 319 213 214 320 /** 215 321 * For each filed defined by the child plugin add it to the appropriate options page/post metabox … … 226 332 foreach($this->fields as $field) { 227 333 228 // get the metabox post_types the field is attached to334 // This field is inside a metabox, that metabox may be use on more than one poswt type, so go get the post types 229 335 $metabox_post_types = $this->diy_get_metabox_post_types($field['metabox']); 230 336 231 // If a post type is set then add the new field to the appropriate metabox .337 // If a post type is set then add the new field to the appropriate metabox 232 338 if ($metabox_post_types!="") { 233 339 // If its not an array, then make it one … … 240 346 } 241 347 } else { 348 // otherwise add the fields to a settings page 242 349 add_settings_field( 243 350 $field['group'], // option identifier … … 251 358 register_setting( $this->options_group, $field['group'], array(&$this,'diy_validate_settings')); 252 359 253 $this->options_meta[ $field['metabox'] ][ $field['group'] ] = $args; 254 360 255 361 // check if this option has previously been created if not apply the defaults 256 362 if (! get_option( $field['group'] ) ) { … … 287 393 */ 288 394 function diy_get_metabox_post_types($id) { 289 if (!is_array($this->metaboxes)) {290 return '';291 }292 395 foreach ($this->metaboxes as $metabox) { 293 396 if ($metabox['id'] == $id) { 294 return $metabox['post_type'];397 return (isset($metabox['post_type']) ? $metabox['post_type'] : '' ); 295 398 } 296 399 } … … 304 407 */ 305 408 function diy_metaboxes() { 306 if (!is_array($this->metaboxes)) {307 return;308 }309 409 foreach ($this->metaboxes as $metabox) { 310 311 if ($metabox['post_type'] != '') { 410 if (isset($metabox['post_type'])) { 312 411 // If a post type is set then add the metabox to the post type 313 412 if (!is_array($metabox['post_type'])) { … … 318 417 319 418 add_meta_box( 320 $metabox['id'],321 $metabox['title'],322 array(&$this,'post_metabox_builder'),323 $metabox_post_type,324 'normal',325 'high',326 $this->meta[$metabox_post_type][$metabox['id']]419 $metabox['id'], 420 $metabox['title'], 421 array(&$this,$metabox['post_callback']), 422 $metabox_post_type, 423 $metabox['context'], 424 'core', 425 $this->meta[$metabox_post_type][$metabox['id']] 327 426 ); 328 427 } … … 331 430 332 431 add_settings_section( 333 $metabox['id'],334 '',335 array(&$this, 'section_null'),336 $this->page432 $metabox['id'], 433 '', 434 array(&$this, 'section_null'), 435 $this->page 337 436 ); 338 437 add_meta_box( 339 $metabox['id'],340 $metabox['title'],341 array(&$this, 'diy_option_field_builder'),342 $this->page,343 'normal',344 'core',345 array('section' => $metabox['id'],'description'=>$metabox['description'])438 $metabox['id'], 439 $metabox['title'], 440 array(&$this, $metabox['option_callback']), 441 $this->page, 442 $metabox['context'], 443 'core', 444 array('section' => $metabox['id'],'description'=>$metabox['description'],'footer'=>$metabox['footer']) 346 445 ); 347 446 … … 351 450 352 451 /** 353 * Vogon constructor354 *355 * @since 0.1356 * @param string $file Contains __FILE__ for the file extending this class357 * @access public358 * @return void359 */360 function __construct($file = __FILE__) {361 // Save the filename of the child plugin362 $this->filename = plugin_basename($file);363 364 // Initialise the plugin if the method has been defined in the extended class365 if ( is_callable( array($this, 'init') ) ) {366 $this->init();367 }368 // Start the plugin369 $this->diy_start();370 371 // Call the child plugins start method372 if ( is_callable( array($this, 'start') ) ) {373 $this->start();374 }375 } // function376 377 378 /**379 452 * Serve the CSS or JS when requested via a URL 380 453 * 381 * @since 0. 1454 * @since 0.0.1 382 455 * @access public 383 456 * @return void 384 457 */ 385 458 public function diy_script_server() { 386 // Check that the query var is set and is the correct value. 387 if (get_query_var( 'diy' ) == 'css') { 388 // Send the headers for a CSS file 389 header("Content-type: text/css"); 390 // output css 391 print $this->diy_css(); 392 exit; 393 } 394 395 // Check that the query var is set and is the correct value. 396 if (get_query_var( 'diy' ) == 'js') { 397 // Send the headers for a javascript file 398 header("Content-type: application/x-javascript"); 399 // output js 400 print $this->diy_js(); 401 exit; 402 } 459 // Check that the query var is set and is the correct value. 460 if (get_query_var( 'diy' ) == 'css') { 461 header("Content-type: text/css"); // Send the headers for a CSS file 462 print $this->diy_css(); // output the css 463 exit; 464 } 465 466 // Check that the query var is set and is the correct value. 467 if (get_query_var( 'diy' ) == 'js') { 468 header("Content-type: application/x-javascript"); // Send the headers for a javascript file 469 print $this->diy_js(); // output js 470 exit; 471 } 403 472 } // function 404 473 405 406 474 /** 407 475 * Setup the query variable used to serve js and css data 408 476 * 409 * @since 0. 1477 * @since 0.0.1 410 478 * @param array $public_query_vars An array of the currently registered query var names 411 479 * @return array Query var names array … … 413 481 */ 414 482 public function diy_query_vars($public_query_vars) { 415 $public_query_vars[] = 'diy'; 416 return $public_query_vars; 417 } // function 418 419 /** 420 * When the plugin is activated update the settings 421 * 422 * @since 0.1 423 * @access public 424 * @todo not currently called anywhere 425 * @return void 426 */ 427 public function diy_activate() { 428 update_option( $this->options_name, $this->options); 429 } // function 430 431 /** 432 * When the plugin is deactivated update the settings 433 * 434 * @since 0.1 435 * @access public 436 * @return void 437 */ 438 public function plugin_deactivate() { 439 440 } // function 441 483 $public_query_vars[] = 'diy'; 484 return $public_query_vars; 485 } // function 486 442 487 /** 443 488 * Create the Options page for the plugin 444 489 * 445 * @since 0. 1490 * @since 0.0.1 446 491 * @access public 447 492 * @return void 448 493 */ 449 494 public function diy_add_options_page() { 450 // Add a theme page or an option page depending on the diy usage451 if ($this->usage == 'theme') {452 $this->page = add_theme_page( __($this->settings_page_title), __($this->settings_page_link), 'edit_theme_options', $this->slug, array(&$this,'diy_render_options_page' ));453 add_action('load-'.$this->page, array(&$this, 'diy_loading_options_page'));454 } else if ($this->usage == 'plugin') {455 $this->page = add_options_page(__($this->settings_page_title), __($this->settings_page_link), 'manage_options', $this->slug, array($this, 'diy_render_options_page'));456 add_filter( 'plugin_action_links', array(&$this, 'diy_add_settings_link'), 10, 2 );457 458 // Run stuff as and when this options page loads459 add_action('load-'.$this->page, array(&$this, 'diy_loading_options_page'));460 }495 // Add a theme page or an option page depending on the diy usage 496 if ($this->usage == 'theme') { 497 $this->page = add_theme_page( __($this->settings_page_title), __($this->settings_page_link), 'edit_theme_options', $this->slug, array(&$this,'diy_render_options_page' )); 498 add_action('load-'.$this->page, array(&$this, 'diy_enqueue_settings_page_scripts')); 499 } else if ($this->usage == 'plugin') { 500 $this->page = add_options_page(__($this->settings_page_title), __($this->settings_page_link), 'manage_options', $this->slug, array($this, 'diy_render_options_page')); 501 add_filter( 'plugin_action_links', array(&$this, 'diy_add_settings_link'), 10, 2 ); 502 503 // Run stuff as and when this options page loads 504 add_action('load-'.$this->page, array(&$this, 'diy_enqueue_settings_page_scripts')); 505 } 461 506 } // function 462 507 … … 464 509 * Runs only on the plugin page load hook, enables the scripts needed for metaboxes 465 510 * 466 * @since 0. 1467 * @access public 468 * @return void 469 */ 470 function diy_ loading_options_page() {511 * @since 0.0.1 512 * @access public 513 * @return void 514 */ 515 function diy_enqueue_settings_page_scripts() { 471 516 wp_enqueue_script('common'); 472 517 wp_enqueue_script('wp-lists'); … … 477 522 * Add a settings link to the plugin list page 478 523 * 479 * @since 0. 1524 * @since 0.0.1 480 525 * @param string $file the filename of the plugin currently being rendered on the installed plugins page 481 526 * @param array $links an array of the current registered links in html format … … 497 542 * On the plugin page make sure there are two columns 498 543 * 499 * @since 0. 1544 * @since 0.0.1 500 545 * @access public 501 546 * @param int $columns … … 503 548 * @return int number of columns 504 549 */ 505 function diy_ options_page_columns($columns, $screen) {550 function diy_settings_page_columns($columns, $screen) { 506 551 if ($screen == $this->page) { 507 552 $columns[$this->page] = 2; … … 514 559 * Create the options page form 515 560 * 516 * @since 0. 1561 * @since 0.0.1 517 562 * @access public 518 563 * @return void … … 559 604 } // function 560 605 561 562 563 606 /** 564 607 * Register some default metaboxes on the plugins options page 565 608 * 566 * @since 0. 1609 * @since 0.0.1 567 610 * @access public 568 611 * @todo This function should use optbox() to define its metaboxes … … 587 630 } // function 588 631 589 590 632 /** 591 633 * Meta box for the documention link and the debugging popup 592 634 * 593 * @since 0. 1635 * @since 0.0.1 594 636 * @access public 595 637 * @return void … … 614 656 print '<li><strong>Diy Path:</strong> ' . $this->diy_path . '</li>'; 615 657 print '<li><strong>Diy URL:</strong> ' . $this->diy_url . '</li>'; 616 print '<li><strong>Meta:</strong> ' . var_export($this->meta,true) . '</li>';617 print '<li><strong>Metaboxes:</strong> ' . var_export($this->metaboxes,true) . '</li>';618 658 print '</div>'; 619 659 } // function 620 660 621 622 661 /** 623 662 * Meta box for the bug reporting info 624 663 * 625 * @since 0. 1664 * @since 0.0.1 626 665 * @access public 627 666 * @return void … … 636 675 * Meta box for displaying social media links 637 676 * 638 * @since 0. 1677 * @since 0.0.1 639 678 * @access public 640 679 * @return void … … 651 690 * Meta box for displaying plugin rating links 652 691 * 653 * @since 0. 1692 * @since 0.0.1 654 693 * @access public 655 694 * @return void … … 666 705 * Register the admin scripts 667 706 * 668 * @since 0. 1707 * @since 0.0.1 669 708 * @access public 670 709 * @return void 671 710 */ 672 711 function diy_scripts_and_styles() { 673 wp_enqueue_script( 'jquery' ); 674 wp_enqueue_script( 'jquery-ui-core' ); 675 wp_enqueue_script( 'jquery-ui-datepicker' ); 676 677 // Register our dynamic css and js files 678 wp_register_style('diy', home_url() .'?diy=css'); 679 wp_register_script('diy', home_url() .'?diy=js', array('jquery','media-upload','thickbox','editor')); 680 681 wp_register_script('gmap','http://maps.google.com/maps/api/js?sensor=false'); 682 683 // Add custom scripts and styles to the plugin/theme page only 684 add_action('admin_print_scripts-' . $this->page, array(&$this, 'diy_admin_scripts')); 685 add_action('admin_print_styles-' . $this->page, array(&$this, 'diy_admin_styles')); 686 687 // Add custom scripts and styles to the post editor pages 688 add_action('admin_print_scripts-post.php', array(&$this, 'diy_admin_scripts')); 689 add_action('admin_print_scripts-post-new.php',array(&$this, 'diy_admin_scripts')); 690 add_action('admin_print_styles-post.php', array(&$this, 'diy_admin_styles')); 691 add_action('admin_print_styles-post-new.php',array(&$this, 'diy_admin_styles')); 692 712 wp_enqueue_script( 'jquery' ); 713 wp_enqueue_script( 'jquery-ui-core' ); 714 wp_enqueue_script( 'jquery-ui-datepicker' ); 715 716 // Register our dynamic css and js files 717 wp_register_style('diy', home_url() .'?diy=css'); 718 wp_register_script('diy', home_url() .'?diy=js', array('jquery','media-upload','thickbox','editor')); 719 720 721 // if admin.js exists in the child plugin include it 722 if (file_exists($this->plugin_path . 'admin.js')) { 723 wp_register_script($this->slug . '-admin' ,$this->plugin_url . 'admin.js'); 724 } 725 726 // if admin.css exists in the child plugin include it 727 if (file_exists($this->plugin_path . 'admin.css')) { 728 wp_register_style($this->slug . '-admin' ,$this->plugin_url . 'admin.css'); 729 } 730 731 732 wp_register_script('gmap','http://maps.google.com/maps/api/js?sensor=false'); 733 734 // Add custom scripts and styles to the plugin/theme page only 735 add_action('admin_print_scripts-' . $this->page, array(&$this, 'diy_admin_scripts')); 736 add_action('admin_print_styles-' . $this->page, array(&$this, 'diy_admin_styles')); 737 738 // Add custom scripts and styles to the post editor pages 739 add_action('admin_print_scripts-post.php', array(&$this, 'diy_admin_scripts')); 740 add_action('admin_print_scripts-post-new.php',array(&$this, 'diy_admin_scripts')); 741 add_action('admin_print_styles-post.php', array(&$this, 'diy_admin_styles')); 742 add_action('admin_print_styles-post-new.php',array(&$this, 'diy_admin_styles')); 693 743 } // function 694 744 … … 696 746 * Add custom styles to this plugins options page only 697 747 * 698 * @since 0. 1748 * @since 0.0.1 699 749 * @access public 700 750 * @return void … … 702 752 function diy_admin_styles() { 703 753 704 // used by media upload 705 wp_enqueue_style('thickbox'); 706 // Enqueue our diy specific css 707 wp_enqueue_style('diy'); 708 // color picker 709 wp_enqueue_style( 'farbtastic' ); 710 } // function 711 754 // used by media upload 755 wp_enqueue_style('thickbox'); 756 // Enqueue our diy specific css 757 wp_enqueue_style('diy'); 758 // color picker 759 wp_enqueue_style( 'farbtastic' ); 760 } // function 712 761 713 762 /** 714 763 * Add scripts globally to all post.php and post-new.php admin screens 715 764 * 716 * @since 0. 1765 * @since 0.0.1 717 766 * @access public 718 767 * @return void 719 768 */ 720 769 function diy_admin_scripts() { 721 // Enqueue our diy specific javascript722 wp_enqueue_script('diy');723 724 // Color picker725 wp_enqueue_script('farbtastic');726 727 // Allow Jquery Chosen728 wp_enqueue_script('suggest');729 730 // Allow usage of the google map api731 wp_enqueue_script('gmap');770 // Enqueue our diy specific javascript 771 wp_enqueue_script('diy'); 772 773 // Color picker 774 wp_enqueue_script('farbtastic'); 775 776 // Allow Jquery Chosen 777 wp_enqueue_script('suggest'); 778 779 // Allow usage of the google map api 780 wp_enqueue_script('gmap'); 732 781 } 733 782 734 783 /** 735 * Define a metabox field and add it to a metabox784 * Define a metabox field, apply the defaults add it to the fields array 736 785 * 737 786 * @param mixed $args array that contains the metabox field definition 738 * @since 0. 1787 * @since 0.0.1 739 788 * @access public 740 789 * @return void 741 790 */ 742 function field($args) { 743 $this->fields[] = $args; 791 function field($group) { 792 // go through each defined field in the group and apply the defaults 793 foreach ($group['fields'] as $field_name => $field_definition) { 794 795 $group['fields'][$field_name] = wp_parse_args($group['fields'][$field_name], $this->field_defaults ); 796 // Save all queiries for later use 797 if ( $group['fields'][$field_name]['wp_query']) { 798 $this->suggest_queries[$group['group']][$field_name] = $group['fields'][$field_name]['wp_query']; 799 } 800 } 801 802 // Apply the field group defaults and store in the fields array 803 $this->fields[] = wp_parse_args($group, $this->field_group_defaults ); 744 804 } // end function 745 805 746 747 /** 748 * Add a meta box to a post type or an options page. 749 * 750 * @since 0.1 806 /** 807 * Define a meta box for a post type or an options page and apply the defaults 808 * 809 * @since 0.0.1 751 810 * @access public 752 811 * @param array $args … … 754 813 */ 755 814 function metabox( $args) { 756 $this->metaboxes[] = $args;815 $this->metaboxes[] = wp_parse_args( $args, $this->metabox_defaults ); 757 816 } // end function 758 817 … … 760 819 * If a height is specified return the inline style to set it 761 820 * 762 * @since 0. 1821 * @since 0.0.1 763 822 * @access public 764 823 * @param string $height the height in pixels … … 766 825 */ 767 826 function height($height) { 768 return ((!empty($height)) ? ' height:'. $height . 'px;' : '');827 return ((!empty($height)) ? ' height:'. $height . 'px;' : ''); 769 828 } // function 770 829 … … 772 831 * If a width is specified return the inline style to set it 773 832 * 774 * @since 0. 1833 * @since 0.0.1 775 834 * @access public 776 835 * @param string $width The width in pixels … … 778 837 */ 779 838 function width($width) { 780 return ((!empty($width)) ? ' width:'. $width . 'px;' : '');839 return ((!empty($width)) ? ' width:'. $width . 'px;' : ''); 781 840 } // function 782 841 … … 784 843 * If a description is given then return the html to display it 785 844 * 786 * @since 0. 1845 * @since 0.0.1 787 846 * @param string $d The text to show for the description 788 847 * @access public … … 790 849 */ 791 850 function description($d) { 792 return ( (!empty($d)) ? '<br />' . '<span class="description">'.$d. '</span>' : '');851 return ( (!empty($d)) ? '<br />' . '<span class="description">'.$d. '</span>' : ''); 793 852 } // function 794 853 … … 796 855 * If any placeholder text is specified then add the html attribute to the element 797 856 * 798 * @since 0. 1857 * @since 0.0.1 799 858 * @param string $p The text to use for the placeholder 800 859 * @access public … … 802 861 */ 803 862 function placeholder($p) { 804 return ( (!empty($p)) ? 'placeholder="' . $p . '"' : '');863 return ( (!empty($p)) ? 'placeholder="' . $p . '"' : ''); 805 864 } // function 806 865 … … 808 867 * If any suffix text is specified then add the html right after the field 809 868 * 810 * @since 0. 1869 * @since 0.0.1 811 870 * @param string $s The text to use for the suffix 812 871 * @access public … … 814 873 */ 815 874 function suffix($s) { 816 return ( (!empty($s)) ? '<span class="field-suffix">' . $s . '</span>' : ''); 817 } // function 818 875 return ( (!empty($s)) ? '<span class="field-suffix">' . $s . '</span>' : ''); 876 } // function 877 878 /** 879 * If any prefix text is specified then add the html right after the field 880 * 881 * @since 0.0.1 882 * @param string $p The text to use for the prefix 883 * @access public 884 * @return void 885 */ 886 function prefix($p) { 887 return ( (!empty($p)) ? '<span class="field-prefix">' . $p . '</span>' : ''); 888 } // function 889 890 /** 891 * If any placeholder text is specified then add the html attribute to the element 892 * 893 * @since 0.0.1 894 * @param string $p The text to use for the placeholder 895 * @access public 896 * @return void 897 */ 898 function required($r) { 899 return ( ($r) ? ' required ' : ''); 900 } // function 901 819 902 /** 820 903 * Build a text input field widget 821 904 * 822 * @since 0. 1905 * @since 0.0.1 823 906 * @param array $args The width, name, value, placeholder and description of the text field 824 907 * @access public … … 826 909 */ 827 910 function text($args) { 828 // $args = $this->apply_name_fix($this->apply_default_args($args)) ;829 echo "<input class='field' type='text' size='57' style='" . $this->width($args['width']) . "' " . $this->placeholder($args['placeholder']) . " name='" . $args['name'] . "' value='" . $args['value'] . "'/>" . $this->suffix($args['suffix']);830 echo $this->description($args['description']);911 // $args = $this->apply_name_fix($this->apply_default_args($args)) ; 912 echo "<input class='field' type='text' size='57' style='" . $this->width($args['width']) . "' " . $this->placeholder($args['placeholder']) . " " . $this->required($args['required']) . " name='" . $args['name'] . "' value='" . $args['value'] . "'/>" . $this->suffix($args['suffix']); 913 echo $this->description($args['description']); 831 914 } // function 832 915 … … 834 917 * Build a datepicker field widget 835 918 * 836 * @since 0. 1919 * @since 0.0.1 837 920 * @param array $args The width, name, value, placeholder and description of the date field 838 921 * @access public … … 840 923 */ 841 924 function date($args) { 842 if (!isset($args['showothermonths'])) { $args['showothermonths'] = 'false'; } 843 if (!isset($args['dateformat'])) { $args['dateformat'] = 'mm/dd/yy'; } 844 if (!isset($args['numberofmonths'])) { $args['numberofmonths'] = '2'; } 845 // Apply the default date parameters in case they are not set 846 echo "<input class='field datepicker' type='text' size='57' style='" . $this->width($args['width']) . "' " . $this->placeholder($args['placeholder']) . " name='" . $args['name'] . "' value='" . $args['value'] . "'" . 847 "data-showothermonths='" . $args['showothermonths']. "' data-dateformat='" . $args['dateformat']. "' data-numberofmonths='" . $args['numberofmonths']. "'" . "/>"; 848 echo $this->description($args['description']); 849 } // function 850 925 if (!isset($args['showothermonths'])) { $args['showothermonths'] = 'false'; } 926 if (!isset($args['dateformat'])) { $args['dateformat'] = 'mm/dd/yy'; } 927 if (!isset($args['numberofmonths'])) { $args['numberofmonths'] = '2'; } 928 // Apply the default date parameters in case they are not set 929 echo "<input class='field datepicker' type='text' size='57' style='" . $this->width($args['width']) . "' " . $this->placeholder($args['placeholder']) . " name='" . $args['name'] . "' value='" . $args['value'] . "'" . 930 "data-showothermonths='" . $args['showothermonths']. "' data-dateformat='" . $args['dateformat']. "' data-numberofmonths='" . $args['numberofmonths']. "'" . "/>"; 931 echo $this->description($args['description']); 932 } // function 851 933 852 934 /** 853 935 * Build a textarea field widget 854 936 * 855 * @since 0. 1937 * @since 0.0.1 856 938 * @param array $args The width, name, value, placeholder and description of the textarea field 857 939 * @access public … … 859 941 */ 860 942 function textarea($args) { 861 echo "<textarea class='field' data-tooltip='" .$args['tooltip'] . "' name='" . $args['name'] . "' style='" . $this->width($args['width']) . " " . $this->height($args['height']) . "' rows='7' cols='50' type='textarea'>" . $args['value'] . "</textarea>";862 echo $this->description($args['description']);943 echo "<textarea class='field' data-tooltip='" .$args['tooltip'] . "' name='" . $args['name'] . "' style='" . $this->width($args['width']) . " " . $this->height($args['height']) . "' rows='7' cols='50' type='textarea'>" . $args['value'] . "</textarea>"; 944 echo $this->description($args['description']); 863 945 } // function 864 946 … … 866 948 * Build a checkbox field widget 867 949 * 868 * @since 0. 1950 * @since 0.0.1 869 951 * @param array $args The width, name, value, placeholder and description of the checkbox field 870 952 * @access public … … 872 954 */ 873 955 function checkbox($args) { 874 echo "<input class='field' name='" . $args['name'] . "' type='checkbox' value='1' "; 875 checked('1', $args['value']); 876 echo " /> <span class='description'>" . $args['description'] . "</span>" ; 877 878 } // function 879 880 956 echo "<input class='field' name='" . $args['name'] . "' type='checkbox' value='1' "; 957 checked('1', $args['value']); 958 echo " /> <span class='description'>" . $args['description'] . "</span>" ; 959 960 } // function 961 962 /** 963 * Build a radio field widget 964 * 965 * @since 0.0.1 966 * @param array $args The width, name, value, placeholder and description of the text field 967 * @return void 968 * @access public 969 */ 970 function radio($args) { 971 echo "<ul>"; 972 foreach ($args['selections'] as $key => $value) { 973 echo "<li><input class='field' type='radio' name='" . $args['name'] . "' " . checked( $args['value'], $key, false ) . " value='" . $key . "' />" . $value . "</li>"; 974 } 975 echo "</ul>"; 976 977 echo $this->description($args['description']); 978 } // function 979 881 980 /** 882 981 * Build a selectbox field widget 883 982 * 884 * @since 0. 1983 * @since 0.0.1 885 984 * @param array $args The width, name, value, placeholder and description of the text field 886 985 * @return void … … 889 988 function select($args) { 890 989 891 if ($args['multiple']) { 892 echo "<select class='optselect field' multiple='true' style='" .$this->width($args['width']) . "' name='" . $args['name'] . "" . "[]'>"; 893 foreach ($args['selections'] as $key => $value) { 894 echo "<option " . (array_search($value , $args['value']) === false ? '' : 'selected' ). " value='" . $key . "'>" . $value . "</option>"; 895 } 896 echo "</select>"; 897 } else { 898 echo "<select class='optselect field' style='" .$this->width($args['width']) . "' name='" . $args['name'] . "'>"; 899 foreach ($args['selections'] as $key => $value) { 900 echo "<option " . ($args['value'] == $key ? 'selected' : '' ). " value='" . $key . "'>" . $value . "</option>"; 901 } 902 echo "</select>"; 903 } 904 echo $this->description($args['description']); 905 } // function 906 990 if ($args['multiple']) { 991 echo "<select class='optselect field' multiple='true' style='" .$this->width($args['width']) . "' name='" . $args['name'] . "" . "[]'>"; 992 foreach ($args['selections'] as $key => $value) { 993 echo "<option " . (array_search($value , $args['value']) === false ? '' : 'selected' ). " value='" . $key . "'>" . $value . "</option>"; 994 } 995 echo "</select>"; 996 } else { 997 echo "<select class='optselect field' style='" .$this->width($args['width']) . "' name='" . $args['name'] . "'>"; 998 foreach ($args['selections'] as $key => $value) { 999 echo "<option " . ($args['value'] == $key ? 'selected' : '' ). " value='" . $key . "'>" . $value . "</option>"; 1000 } 1001 echo "</select>"; 1002 } 1003 echo $this->description($args['description']); 1004 } // function 1005 1006 1007 function editor($args) { 1008 $settings=array('textarea_name' => $args['name']); 1009 wp_editor( $args['value'], 'testeditor', $settings ); 1010 } 1011 1012 907 1013 /** 908 1014 * Render a google map 909 1015 * 910 * @since 0. 11016 * @since 0.0.1 911 1017 * @access public 912 1018 * @param array $args … … 916 1022 global $post; 917 1023 // build the html map element 918 echo '< div id="map-' . $args['name'] . '" class="gmap field" data-zoom="5" data-lat="" data-long="" data-latfield="' . $args['latfield'] . '" data-longfield="' . $args['longfield'] . '" style="' .$this->height($args['height']) . '" ></div>';1024 echo '<input type="hidden" name="' . $args['name'] . '" value="1" /><div id="map-' . $args['name'] . '" class="gmap field" data-zoom="5" data-lat="" data-long="" data-latfield="' . $args['latfield'] . '" data-longfield="' . $args['longfield'] . '" style="' .$this->height($args['height']) . '" ></div>'; 919 1025 } // end function map 920 1026 921 922 1027 /** 923 1028 * Render a color picker field widget 924 1029 * 925 * @since 0. 11030 * @since 0.0.1 926 1031 * @param array $args 927 1032 * @access public … … 939 1044 * Retrieve the ID number of an image/file asset 940 1045 * 941 * @since 0. 11046 * @since 0.0.1 942 1047 * @access public 943 1048 * @param string $image_src … … 951 1056 } 952 1057 953 954 1058 /** 955 1059 * Render an attachment field widget 956 1060 * 957 * @since 0. 11061 * @since 0.0.1 958 1062 * @param array $args 959 1063 * @access public … … 966 1070 967 1071 // show a preview 968 $this->attachment_preview($args['value']); 1072 if ($args['preview']) { 1073 $this->attachment_preview($args['value']); 1074 } 969 1075 echo $this->description($args['description']); 970 1076 } // function 971 1077 972 973 1078 /** 974 1079 * Generate or display a thumbnail of the chosen file, needs a good cleanup 975 1080 * 976 * @since 0. 11081 * @since 0.0.1 977 1082 * @param string $original 978 1083 * @access public … … 1004 1109 } // end function 1005 1110 1006 1007 1111 /** 1008 1112 * Given a file return it as a url 1009 1113 * 1010 * @since 0. 11114 * @since 0.0.1 1011 1115 * @access public 1012 1116 * @param string $file a filename … … 1020 1124 * Render a suggest posts field widget 1021 1125 * 1022 * @since 0. 11126 * @since 0.0.1 1023 1127 * @access public 1024 1128 * @param array $args field arguments … … 1026 1130 */ 1027 1131 function suggest($args) { 1028 echo "<input type='text' class='suggest field' data-id='" . $args['value'] . "' data-suggest='" . $args['suggestions'] . "' size='57' style='" . $this->width($args['width']) . "' " . $this->placeholder($args['placeholder']) . " name='" . $args['name'] . "' value='" . $this->suggest_get_title($args['value']) . "'/>"; 1132 if(isset($args['wp_query']['post_type'])) { 1133 $mode = 'posts'; 1134 } else { 1135 $mode = 'users'; 1136 } 1137 1138 echo "<input type='text' class='suggest field' data-id='" . $args['value'] . "' data-group='" . $args['group'] . "' data-field='" . $args['field'] . "' size='57' style='" . $this->width($args['width']) . "' " . $this->placeholder($args['placeholder']) . " name='" . $args['name'] . "' value='" . $this->suggest_get_title($args['value'],$mode) . "'/>"; 1029 1139 echo $this->description($args['description']); 1140 1030 1141 } // function 1031 1142 … … 1033 1144 * Render a suggest user field widget 1034 1145 * 1035 * @since 0. 11146 * @since 0.0.1 1036 1147 * @access public 1037 1148 * @param array $args field arguments … … 1039 1150 */ 1040 1151 function suggest_users($args) { 1041 echo "<input type='text' class='suggest field' data-id='" . $args['value'] . "' data-suggest='" . $args['suggestions'] . "' size='57' style='" . $this->width($args['width']) . "' " . $this->placeholder($args['placeholder']) . " name='" . $args['name'] . "' value='" . $this->suggest_get_title($args['value']) . "'/>";1152 echo "<input type='text' class='suggest field' data-id='" . $args['value'] . "' data-suggest='" . $args['suggestions'] . "' data-group='" . $args['group'] . "' data-field='" . $args['field'] . "' size='57' style='" . $this->width($args['width']) . "' " . $this->placeholder($args['placeholder']) . " name='" . $args['name'] . "' value='" . $this->suggest_get_title($args['value']) . "'/>"; 1042 1153 echo $this->description($args['description']); 1043 1154 } // function … … 1046 1157 * Render a suggest users field widget 1047 1158 * 1048 * @since 0. 11159 * @since 0.0.1 1049 1160 * @access public 1050 1161 * @param array $args field arguments … … 1059 1170 * Given an id show it along with the title in the autocmoplete textbox 1060 1171 * 1061 * @since 0. 11172 * @since 0.0.1 1062 1173 * @see suggest 1063 1174 * @param string $id … … 1065 1176 * @access public 1066 1177 */ 1067 function suggest_get_title($id) { 1068 if (empty($id)) { return ""; } 1069 return get_the_title($id) . " [#". $id ."]"; 1178 function suggest_get_title($id, $mode='posts') { 1179 if ($mode == 'posts') { 1180 if (empty($id)) { return ""; } 1181 return get_the_title($id) . " [#". $id ."]"; 1182 } else { 1183 if (empty($id)) { return ""; } 1184 return get_the_author_meta('user_nicename',$id) . " [*" . $id . "]"; 1185 } 1070 1186 } 1071 1187 … … 1073 1189 * Given an id show it along with the title in the autocmoplete textbox e.g. Title [# 101] 1074 1190 * 1075 * @since 0. 11191 * @since 0.0.1 1076 1192 * @access public 1077 1193 * @param string $id A post_id … … 1089 1205 * Ajax callback function to return list of post types 1090 1206 * 1091 * @since 0. 11207 * @since 0.0.1 1092 1208 * @access public 1093 1209 * @return void 1094 1210 */ 1095 1211 function diy_suggest_posts_callback() { 1096 global $wpdb, $post; 1097 1098 $posttype = $wpdb->escape($_GET['type']); 1099 $in = $wpdb->escape($_GET['q']); 1100 1101 $query = "SELECT ID from $wpdb->posts where post_type = '$posttype' AND post_title like '%$in%' "; 1102 $mypostids = $wpdb->get_col($query); 1103 1104 foreach ($mypostids as $key => $value) { 1105 print get_the_title($value) . " [#" . $value . "]" . "\n"; 1212 global $wpdb; 1213 1214 $group = $wpdb->escape($_GET['group']); 1215 $field = $wpdb->escape($_GET['field']); 1216 $in = $wpdb->escape($_GET['q']); 1217 1218 // get the custom query from the saved field definition 1219 $custom_args = array(); 1220 if (isset($this->suggest_queries[$group][$field])) { 1221 $custom_args = $this->suggest_queries[$group][$field]; 1222 } 1223 1224 // if we are searching for posts 1225 if (isset($custom_args['post_type'])) { 1226 $defaults = array( 1227 'post_title_like' => $in, 1228 'post_type' => 'post', 1229 ); 1230 1231 $args = wp_parse_args($custom_args, $defaults); 1232 1233 $the_query = new WP_Query($args); 1234 // The Loop 1235 while ( $the_query->have_posts() ) : $the_query->the_post(); 1236 echo get_the_title(). " [#" . get_the_ID() . "]" . "\n"; 1237 1238 endwhile; 1239 } else { 1240 $defaults = array( 1241 'search'=>'*' . $in . '*', 1242 ); 1243 1244 $args = wp_parse_args($custom_args, $defaults); 1245 1246 // we are searching for users 1247 $wp_user_search = new WP_User_Query( $args ); 1248 $users = $wp_user_search->get_results(); 1249 1250 foreach ($users as $user) { 1251 print $user->user_nicename . " [*" .$user->ID . "]" . "\n"; 1106 1252 } 1107 die(); // this is required to return a proper result 1108 } // function 1109 1110 1253 } 1254 die(); // this is required to return a proper result 1255 } // function 1256 1257 /** 1258 * Modify the query WHERE clause when performing a suggest ajax request 1259 * 1260 * @since 0.0.2 1261 * @access public 1262 * @return void 1263 */ 1264 function diy_modify_posts_where( $where, &$wp_query ) { 1265 global $wpdb; 1266 // only modify the query when post_title_like has been passed in 1267 if ( $post_title_like = $wp_query->get( 'post_title_like' ) ) { 1268 $where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'%' . esc_sql( like_escape( $post_title_like ) ) . '%\''; 1269 } 1270 return $where; 1271 } // function 1272 1273 /** 1274 * Callback field widget 1275 * 1276 * @since 0.0.1 1277 * @access public 1278 * @return void 1279 */ 1111 1280 function callback($args) { 1112 1281 echo $this->{$args['function']}(); … … 1117 1286 * Return a list of posts from a post type 1118 1287 * 1119 * @since 0. 11288 * @since 0.0.1 1120 1289 * @access public 1121 1290 * @param string $type The name of a registered post type … … 1123 1292 */ 1124 1293 function get_by_type($type) { 1125 $output = array(); 1126 $posts_array = get_posts( 'post_type=' . $type ); 1127 foreach( $posts_array as $post ) { 1128 setup_postdata($post); 1129 $output[$post->ID] = $post->post_title ; 1130 } 1131 return $output; 1132 } // function 1133 1134 1294 $output = array(); 1295 $posts_array = get_posts( 'post_type=' . $type ); 1296 foreach( $posts_array as $post ) { 1297 setup_postdata($post); 1298 $output[$post->ID] = $post->post_title ; 1299 } 1300 return $output; 1301 } // function 1135 1302 1136 1303 /** 1137 1304 * The Callback function to build a post metabox based on the arguments passed in from add_meta_box() 1138 1305 * 1139 * @since 0. 11306 * @since 0.0.1 1140 1307 * @access public 1141 1308 * @param array $data … … 1144 1311 */ 1145 1312 function post_metabox_builder($data,$args) { 1146 global $post; 1147 1148 // print var_export($args['args'],true); 1149 $args=$args['args'] ; 1150 1151 if (!is_array($args)) {$args = array();} 1152 1153 foreach( $args as $field_group => $group) { 1154 echo "<table class='form-table'><tr><th scope='row'><strong>" . $group['title'] . "</strong></th><td>"; 1155 1156 // Load up the current value 1157 $group_values = get_post_meta($post->ID, $group['group'], true); 1158 1159 $this->print_field_group($group,$group_values); 1160 // if we have a repeatble group then add a button 1161 1162 // call the function named in the type field 1163 // $this->{$meta_box['type']}($args); 1164 1165 1166 echo "</td></tr></table>"; 1167 1168 1169 } // end for 1170 1313 global $post; 1314 1315 // print var_export($args['args'],true); 1316 $args=$args['args'] ; 1317 1318 if (!is_array($args)) {$args = array();} 1319 1320 foreach( $args as $field_group => $group) { 1321 if ($group['style'] == "block") { 1322 echo "<div class='form-div'>"; 1323 } else { 1324 echo "<table class='form-table'><tr><th scope='row'><strong>" . $group['title'] . "</strong></th><td>"; 1325 } 1326 // Load up the current value 1327 $group_values = get_post_meta($post->ID, $group['group'], true); 1328 1329 $this->print_field_group($group,$group_values); 1330 1331 if ($group['style'] == "block") { 1332 echo "</div>"; 1333 } else { 1334 echo "</td></tr></table>"; 1335 } 1336 } // end for 1171 1337 } 1172 1338 … … 1174 1340 * Print a field group 1175 1341 * 1176 * @since 0. 11342 * @since 0.0.1 1177 1343 * @access public 1178 1344 * @param array $group … … 1180 1346 * @return void 1181 1347 */ 1182 function print_field_group($group,$group_values) { 1348 function print_field_group($group,$group_values) { 1183 1349 // if there are more than one field turn individual field titles on 1184 1350 if (count( $group['fields']) > 1) {$is_group = true;} else {$is_group = false;} … … 1194 1360 print '<ul class="field-group" data-set="' . $counter . '">'; 1195 1361 foreach( $group['fields'] as $field_name => $field) { 1196 print '<li>'; 1362 1363 print '<li class="field-' . $field_name . '">'; 1197 1364 if ($is_group) { print "<label class='" . ($field['label_style'] == 'block' ? "" : "fl" ) . "' style='" . ($field['label_width'] ? "width:" . $field['label_width'] . "px" : "" ) . "'>" . $field['title'] . "</label>";} 1198 1365 … … 1200 1367 $field['name'] = "" . $group['group'] . "[" . $counter . "][" . $field_name . "]"; 1201 1368 $field['id'] = $group['group'] . "-" . $counter . "-" . $field_name; 1369 1370 $field['group'] = $group['group']; 1371 $field['field'] = $field_name; 1202 1372 1203 1373 // Set the current value of the field … … 1226 1396 1227 1397 1228 if (($group['max'] > 1) && ($sets != $group['max'])) {print "<a href='#' class='another-group button '>Add Another</a>"; }1398 if (($group['max'] > 1) && ($sets != $group['max'])) {print "<a href='#' class='another-group button-primary'>Add Another</a>"; } 1229 1399 1230 1400 print '<div style="clear:both;"></div></div>'; … … 1234 1404 * Save the post meta box field data 1235 1405 * 1236 * @since 0. 11406 * @since 0.0.1 1237 1407 * @access public 1238 1408 * @param string $post_id The post id we are saving … … 1251 1421 1252 1422 // Check some permissions 1253 if ( 'page' == $_POST['post_type'] ) {1254 if ( !current_user_can( 'edit_page', $post_id ))1255 return $post_id;1423 if ( isset($_POST['post_type']) && 'page' == $_POST['post_type'] ) { 1424 if ( !current_user_can( 'edit_page', $post_id )) 1425 return $post_id; 1256 1426 } else { 1257 if ( !current_user_can( 'edit_post', $post_id ))1258 return $post_id;1427 if ( !current_user_can( 'edit_post', $post_id )) 1428 return $post_id; 1259 1429 } 1260 1430 1261 1431 // only save if we have something to save 1262 if (isset($_POST['post_type']) && $_POST['post_type'] && $this->meta[$_POST['post_type']]) {1432 if (isset($_POST['post_type']) && $_POST['post_type'] && isset($this->meta[$_POST['post_type']]) ) { 1263 1433 1264 1434 // go through each of the registered post metaboxes … … 1269 1439 1270 1440 // Get the post data for this field group 1271 $data = $_POST[$group['group']]; 1441 if (isset($_POST[$group['group']])) { 1442 $data = $_POST[$group['group']]; 1443 } else { 1444 $data = ""; 1445 } 1446 1272 1447 1273 1448 // Convert autosuggest value to a post id … … 1309 1484 * Print the form field group on the settings page 1310 1485 * 1311 * @since 0. 11486 * @since 0.0.1 1312 1487 * @access public 1313 1488 * @param array $args … … 1325 1500 * Build the meta box content and print the fields 1326 1501 * 1327 * @since 0. 11502 * @since 0.0.1 1328 1503 * @access public 1329 1504 * @param array $data … … 1342 1517 do_settings_fields( $this->page, $args['args']['section'] ); 1343 1518 echo '</table>'; 1519 1520 // Print the metabox description at the top of the metabox 1521 if ($args['args']['footer']) { 1522 echo '<div class="options-footer" style="padding:10px; line-height: 1.6;">'; 1523 echo $args['args']['footer']; 1524 echo '</div>'; 1525 } 1344 1526 } // function 1345 1527 … … 1347 1529 * Convert all autocomplete fields to a post_id [# ] 1348 1530 * 1349 * @since 0. 11531 * @since 0.0.1 1350 1532 * @access public 1351 1533 * @param array $data the array of options … … 1369 1551 } 1370 1552 } 1553 1554 // if the [*#* string is found in the data 1555 if (strlen(strstr($data[$key][$field],'[*'))>0) { 1556 // extract it [# ] 1557 preg_match('/.*\[\*(.*)\]/', $data[$key][$field], $matches); 1558 $data[$key][$field] = $matches[1]; 1559 // Retrieve matching data from the posts table 1560 $result = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->users AS wpusers WHERE wpusers.ID = '" . $data[$key][$field] . "'"); 1561 if ($result == 0) { 1562 $data[$key][$field]=''; 1563 } 1564 } 1565 1371 1566 } // end foreach 1372 1567 } // end foreach … … 1381 1576 * The CSS is iself served instead of as separate file to keep the Diy class as a single file 1382 1577 * 1383 * @since 0. 11578 * @since 0.0.1 1384 1579 * @access public 1385 1580 * @return void … … 1387 1582 function diy_css() { 1388 1583 // Repeatable field group buttons 1389 print '.field-group { padding: 0px 0 0px 0; margin-top: 0px; margin-bottom: 0px; }';1584 print '.field-group { padding: 0px 0 0px 0; margin-top: 0px; margin-bottom: 0px; position:relative;}'; 1390 1585 print '.field-group-multi .field-group {border-bottom: 1px solid #E3E3E3; margin: 0px 0 10px 0; }'; 1391 1586 print '.field-group-sortable .field-group {padding-left:20px; cursor: move; background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAYAAABy6+R8AAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/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g+q/NDMXI5/nibZt0fc9VHxb0zShrmtc14VlWTDPc3IexxHDMKjPzMwsWmthZsnuBCDpcBxHUp++yj3svu/3DkmkLygGu657AUWVfsJvAPNNleEaizeIAAAAAElFTkSuQmCC) no-repeat 0px 0px;}'; … … 1518 1713 print '.ui-icon-circle-triangle-e {background: transparent url(../../../wp-admin/images/arrows.png) no-repeat 6px -103px; 1519 1714 width: 25px; float: right; height:25px;}'; 1520 1715 1716 // Form Validation Images from http://www.woothemes.com/2010/08/woocons1/ 1717 print 'input:required:invalid, input:focus:invalid { 1718 background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNS4xIFdpbmRvd3MiIH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URCWRrt9rFUXkzMxQyG3K60VpZQWf4y3rVg5VwFnUI+0b7P+2A3J9E1oIJ5eDbfCZ8FKW5QG9d/wFf4mo5K5DwFmW7hDs8RA+Pn44NZRPvU+G4dZV6lFbxbXLj10USWTRNFqQiEEOrJANGH3bh3caAnZWt+Zm0jhfTRK3pTWJ1O/8ED0rPOpXexWwj4x8Oh9QA7TNUhvW23yWFTCdf4QvSZvDP2rwADANhwFarl2kEzAAAAAElFTkSuQmCC"); 1719 background-position: right 5px; 1720 background-repeat: no-repeat; 1721 padding-right: 18px; 1722 } 1723 input:required:valid { 1724 background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNS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NKZBTAz7hHSoSrVmMReZRyYfxNCZTiK2Y2V7FTMbiyjjq0igElQ9BzujGhrTYHcv8EmUQt2qRYPVXob5WAD7izLqSssws/kL5XwNlIKOrJYDS/4kUQobGjODlJydXPOtB3iOI0SVmDiwJMbw0bcKrtRJsAKZKgeVfCmHcqnGNCiyI/DbvzG+F/fDTdJmCWqxcrA5eGQVBbKSB2tljB7lUC7VUC1Dl6l1kAGZEM4GjF6+c2K8uaXBlVetJMSDRbOzDCkN68vbwZn3WxPxbbywkPVZ8uoHBgzDmNt1zIWhswO2+22DFeec1SW1FItHMqFFrzC38l15Iwbx9YhraP8xYA6DLSJVSR7oMNACZLqUpLJ076j2yOCPAAMAeINpp0KtkLIAAAAASUVORK5CYII="); 1725 background-position: right 5px; 1726 background-repeat: no-repeat; 1727 padding-right: 18px; 1728 }'; 1729 // Add any plugin defined css 1730 print apply_filters('diy_css',''); 1521 1731 } // end function 1522 1732 … … 1527 1737 * The JS is self served instead of as separate file to keep the diy as a single file 1528 1738 * 1529 * @since 0. 11739 * @since 0.0.1 1530 1740 * @access public 1531 1741 * @return void … … 1537 1747 1538 1748 // Apply sorting to DOM elements where class is field-group-sortable 1539 print ' $(".field-group-sortable").sortable({1749 print ' jQuery(".field-group-sortable").sortable({ 1540 1750 update: function(event,ui) { 1541 1751 reset_field_order(this); … … 1562 1772 }); 1563 1773 // Add the delete buttons back in 1564 if (index != 0) { $("<a href=\'#\' class=\'delete-group button\'>Delete </a>").appendTo($(this)); }1774 if (index != 0) { jQuery("<a href=\'#\' class=\'delete-group button\'>Delete </a>").appendTo(jQuery(this)); } 1565 1775 }); 1566 1776 … … 1570 1780 // Add the add another button if needed 1571 1781 if (fieldcount < max) { 1572 jQuery(wrapper).find(".field-group:last").after("<a href=\'#\' class=\'another-group button \'>Add Another</a>")1782 jQuery(wrapper).find(".field-group:last").after("<a href=\'#\' class=\'another-group button-primary\'>Add Another</a>") 1573 1783 } 1574 1784 … … 1576 1786 1577 1787 // if the delete group button is pressed 1578 print ' $(".delete-group").live("click", function (event) {1788 print ' jQuery("body").on("click",".delete-group", function (event) { 1579 1789 event.preventDefault(); 1580 1790 1581 1791 // Save a reference to the outer wrapper 1582 var wrapper = $(this).closest(".field-group-wrapper");1792 var wrapper = jQuery(this).closest(".field-group-wrapper"); 1583 1793 1584 1794 // remove the one we want to delete 1585 $(this).closest(".field-group").remove();1795 jQuery(this).closest(".field-group").remove(); 1586 1796 1587 1797 // Reset the field ordering … … 1590 1800 1591 1801 // If the add group button is pressed 1592 print ' $("body").on("click",".another-group",function(event) {1802 print 'jQuery("body").on("click",".another-group",function(event) { 1593 1803 event.preventDefault(); 1594 1595 var wrapper = $(this).closest(".field-group-wrapper");1804 1805 var wrapper = jQuery(this).closest(".field-group-wrapper"); 1596 1806 1597 1807 var newgroup = jQuery(wrapper).find(".field-group:first").clone(); 1598 1808 1599 1809 // Clear the attributes 1600 1601 newgroup.find(".field:not([type=checkbox])").attr("value",""); 1602 1810 newgroup.find(".field:not([type=checkbox],[type=radio])").attr("value","").attr("checked",false); 1811 newgroup.find(".field[type=radio]:first").attr("checked",true); 1603 1812 newgroup.find(".field").each(function (index) { 1604 1813 1605 1814 // Date picker gives the input field an id so we must remove it here 1606 if ( $(this).hasClass("dated")) { $(this).attr("id",""); }1815 if (jQuery(this).hasClass("dated")) { jQuery(this).attr("id",""); } 1607 1816 1608 1817 // remove the classes so the new fields get rebound with handlers 1609 $(this).removeClass("suggested picked hasDatepicker dated"); 1818 jQuery(this).removeClass("suggested picked hasDatepicker dated"); 1819 1820 // Change the field index to a high number temporarily so that we can insert it before field reordering 1821 jQuery(this).attr("name", 1822 jQuery(this).attr("name").replace(/\[(.*)\]\[/,"[9999999][") 1823 ); 1610 1824 1611 1825 }); 1612 1826 1613 newgroup.insertBefore( $(this));1827 newgroup.insertBefore(jQuery(this)); 1614 1828 1615 1829 // Reset the field ordering … … 1637 1851 var imgurl, aurl; 1638 1852 if (jQuery(".attachment.active").length > 0) { 1639 console.log(html);1853 1640 1854 imgurl = jQuery("img",html).attr("src"); 1641 1855 aurl = jQuery("a","<div>" + html + "</div>").attr("href"); … … 1660 1874 print ' function () { '; 1661 1875 print ' jQuery(this).suggest('; 1662 print ' ajaxurl + "?action=suggest_action& type=" + jQuery(this).data("suggest")';1876 print ' ajaxurl + "?action=suggest_action&group=" + jQuery(this).data("group") + "&field=" + jQuery(this).data("field") + ""'; 1663 1877 print ' );'; 1664 1878 print ' jQuery(this).addClass("suggested");'; … … 1714 1928 1715 1929 // for each div with the class of gmap 1716 $(".gmap").each(function(index){1930 jQuery(".gmap").each(function(index){ 1717 1931 var map = []; 1718 1932 1719 1933 // populate the data attributes 1720 var savedlat = $("[name=\"" + $(this).data("latfield") + "\"]").val();1721 var savedlong = $("[name=\"" + $(this).data("longfield") + "\"]").val();1934 var savedlat = jQuery("[name=\"" + jQuery(this).data("latfield") + "\"]").val(); 1935 var savedlong = jQuery("[name=\"" + jQuery(this).data("longfield") + "\"]").val(); 1722 1936 1723 1937 // Setup the map center/marker location … … 1726 1940 // define the map options 1727 1941 var options = { 1728 zoom: $(this).data("zoom"),1942 zoom: jQuery(this).data("zoom"), 1729 1943 center: latlng, 1730 1944 mapTypeId: google.maps.MapTypeId.ROADMAP, … … 1734 1948 1735 1949 1736 map[index] = new google.maps.Map(document.getElementById( $(this).attr("id") ), options);1950 map[index] = new google.maps.Map(document.getElementById( jQuery(this).attr("id") ), options); 1737 1951 1738 1952 // stick the map marker on the map … … 1745 1959 // add the map clickerooner 1746 1960 1747 map[index].latfield = $(this).data("latfield");1748 map[index].longfield = $(this).data("longfield");1961 map[index].latfield = jQuery(this).data("latfield"); 1962 map[index].longfield = jQuery(this).data("longfield"); 1749 1963 1750 1964 google.maps.event.addListener(map[index],"click", function(location) { … … 1773 1987 1774 1988 });'; 1775 1989 // Add any plugin defined admin js 1990 print apply_filters('diy_js',''); 1776 1991 // end closure 1777 1992 print '});'; 1993 1994 1778 1995 1779 1996 } // end function 1780 1997 } // end class definition 1781 1998 1782 function diy_option($group,$id,$instance = 0) { 1783 $result = array(); 1999 /** 2000 * Return an instance of an field from the database 2001 * 2002 * @since 0.0.1 2003 * @access public 2004 * @return void 2005 */ 2006 function diy_option($group,$field,$instance = 0) { 2007 // retrieve the option 1784 2008 $result = get_option($group); 1785 1786 if ( is_array($result)) {1787 return $result[$instance][$id];2009 // if the value has been saved/set 2010 if ((bool) $result[$instance][$field]) { 2011 return $result[$instance][$field]; 1788 2012 } else { 1789 return ''; 2013 // return an empty string like get_post_meta does if the key is not set 2014 return ''; 1790 2015 } 1791 2016 } // end function 1792 2017 1793 2018 /** 2019 * Return an instance of an post_meta field from the database 2020 * 2021 * @since 0.0.1 2022 * @access public 2023 * @return void 2024 */ 1794 2025 function diy_post_meta($post_id,$group,$field,$instance = 0) { 1795 $result = array(); 1796 $result = get_post_meta($post_id,$group,true); 1797 1798 if (is_array($result)) { 1799 return $result[$instance][$field]; 1800 } else { 1801 return ''; 1802 } 2026 // retrieve the option 2027 $result = get_post_meta($post_id,$group,true); 2028 2029 // if the value has been saved/set 2030 if ((bool) $result[$instance][$field]) { 2031 return $result[$instance][$field]; 2032 } else { 2033 // return an empty string like get_post_meta does if the key is not set 2034 return ''; 2035 } 1803 2036 } // end function 1804 2037 -
diy/trunk/diytests.php
r498144 r500696 26 26 */ 27 27 28 // Check if the DIY framework plugin is installed and prompt if necessary 29 if (!in_array( 'diy/diy.php', (array) get_option( 'active_plugins', array() )) ) { 30 add_action('admin_notices', create_function('','echo "<div class=\"updated\"><p>This plugin requires the <em>Diy Plugin Framework</em> to operate, <a href=\"http://wordpress.org/extend/plugins/diy/\">install it now?</a></p></div>"; ')); 31 } // end if 32 28 33 add_action( 'diy_init', 'testdiy_init' ); 34 29 35 /** 30 36 * Define the entire functionality inside the diy_init action which only called … … 95 101 ); 96 102 97 // Text field test 98 $this->field( 99 array( 100 "metabox" => "field-tests-single", // the id of the metabox this field resides inside 101 "group" => "test-text-single", // The form field name 102 "title" => "Text", // Title used when prompting for input 103 "max" => "1", 104 "fields" => array( 105 "value" => array( 106 "type" => "text", 107 "description" => "Text Description", 108 ) 109 ) // end fields 110 ) // end array 111 ); 103 // Text field test 104 $this->field( 105 array( 106 "metabox" => "field-tests-single", // the id of the metabox this field resides inside 107 "group" => "test-text-single", // The form field name 108 "title" => "Text", // Title used when prompting for input 109 "max" => "1", 110 "fields" => array( 111 "value" => array( 112 "type" => "text", 113 "description" => "Text Description", 114 "required" => true, 115 "placeholder" => 'This is a required field with a placeholder', 116 ) 117 ) // end fields 118 ) // end array 119 ); 112 120 113 121 // Textarea field test … … 138 146 "type" => "select", 139 147 "description" => "Select Description", 148 "selections" => array("0"=>"0","1"=>"1","2"=>"2") 149 ) 150 ) // end fields 151 ) // end array 152 ); 153 154 // Select box multiple field test 155 $this->field( 156 array( 157 "metabox" => "field-tests-single", // the id of the metabox this field resides inside 158 "group" => "test-radio-single", // The form field name 159 "title" => "Radio", // Title used when prompting for input 160 "max" => "1", 161 "fields" => array( 162 "value" => array( 163 "type" => "radio", 164 "description" => "Multi Radio Description", 140 165 "selections" => array("0"=>"0","1"=>"1","2"=>"2") 141 166 ) … … 222 247 "type" => "suggest", 223 248 "description" => "Suggest Posts Description", 224 " suggestions" => "post",249 "wp_query" => array("post_type" => "post"), 225 250 ) 226 251 ) // end fields … … 233 258 "metabox" => "field-tests-single", // the id of the metabox this field resides inside 234 259 "group" => "test-suggest-pages-single", // The form field name 235 "title" => "Suggest P osts", // Title used when prompting for input260 "title" => "Suggest Pages", // Title used when prompting for input 236 261 "max" => "1", 237 262 "fields" => array( … … 239 264 "type" => "suggest", 240 265 "description" => "Suggest Pages Description", 241 "suggestions" => "page", 242 ) 243 ) // end fields 244 ) // end array 245 ); 266 "wp_query" => array("post_type" => "page"), 267 ) 268 ) // end fields 269 ) // end array 270 ); 271 272 273 // Suggest pages field test 274 $this->field( 275 array( 276 "metabox" => "field-tests-single", // the id of the metabox this field resides inside 277 "group" => "test-suggest-all-users-single", // The form field name 278 "title" => "Suggest All Users", // Title used when prompting for input 279 "max" => "1", 280 "fields" => array( 281 "value" => array( 282 "type" => "suggest", 283 "description" => "Suggest All Users Description", 284 "wp_query" => array('orderby' => 'display_name'), 285 ) 286 ) // end fields 287 ) // end array 288 ); 289 290 // Suggest pages field test 291 $this->field( 292 array( 293 "metabox" => "field-tests-single", // the id of the metabox this field resides inside 294 "group" => "test-suggest-subscribers-users-single", // The form field name 295 "title" => "Suggest Subscribers", // Title used when prompting for input 296 "max" => "1", 297 "fields" => array( 298 "value" => array( 299 "type" => "suggest", 300 "description" => "Suggest Subscribers Description", 301 "wp_query" => array('role' => 'subscriber'), 302 ) 303 ) // end fields 304 ) // end array 305 ); 306 246 307 247 308 // Suggest location field test … … 290 351 ) // end array 291 352 ); 353 354 355 $this->field( 356 array( 357 "metabox" => "field-tests-single", // the id of the metabox this field resides inside 358 "group" => "test-suggest-pages-single2", // The form field name 359 "title" => "Suggest Posts", // Title used when prompting for input 360 "max" => "1", 361 "fields" => array( 362 "value" => array( 363 "type" => "suggest", 364 "description" => "Suggest Posts Custom Filter", 365 "wp_query" => array("post_type" => "page"), 366 ) 367 ) // end fields 368 ) // end array 369 ); 292 370 293 371 // MULTI FIELD TESTS … … 385 463 "type" => "select", 386 464 "description" => "Multi Select Description", 465 "selections" => array("0"=>"0","1"=>"1","2"=>"2") 466 ) 467 ) // end fields 468 ) // end array 469 ); 470 471 // Select box multiple field test 472 $this->field( 473 array( 474 "metabox" => "field-tests-multi", // the id of the metabox this field resides inside 475 "group" => "test-radio-multi", // The form field name 476 "title" => "Radio", // Title used when prompting for input 477 "max" => "5", 478 "fields" => array( 479 "value" => array( 480 "type" => "radio", 481 "description" => "Multi Radio Description", 387 482 "selections" => array("0"=>"0","1"=>"1","2"=>"2") 388 483 ) … … 467 562 "type" => "suggest", 468 563 "description" => "Suggest Posts Description", 469 " suggestions" => "post",564 "wp_query" => array("post_type" => "post"), 470 565 ) 471 566 ) // end fields … … 486 581 ); 487 582 488 $this->metabox( 489 array( 490 'id' => 'field-post-tests-multi', 491 'title' => 'Field Post Tests (Multi)', 492 'post_type' => array('post','page') 493 ) 494 ); 583 495 584 496 585 $this->field( 497 586 array( 498 587 "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside 499 "group" => " test-checkbox-single", // The form field name588 "group" => "post-tests-checkbox-single", // The form field name 500 589 "title" => "Checkbox", // Title used when prompting for input 501 590 "max" => "1", … … 512 601 array( 513 602 "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside 514 "group" => " test-text-single", // The form field name603 "group" => "post-tests-text-single", // The form field name 515 604 "title" => "Text", // Title used when prompting for input 516 605 "max" => "1", … … 527 616 array( 528 617 "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside 529 "group" => " test-textarea-single", // The form field name618 "group" => "post-tests-textarea-single", // The form field name 530 619 "title" => "Textarea", // Title used when prompting for input 531 620 "max" => "1", 621 "style" => "block", 532 622 "fields" => array( 533 623 "value" => array( … … 542 632 array( 543 633 "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside 544 "group" => " test-select-single", // The form field name634 "group" => "post-tests-select-single", // The form field name 545 635 "title" => "Select", // Title used when prompting for input 546 636 "max" => "1", … … 554 644 ) // end array 555 645 ); 556 557 $this->field( 558 array( 559 "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside 560 "group" => " test-color-single", // The form field name646 647 $this->field( 648 array( 649 "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside 650 "group" => "post-tests-color-single", // The form field name 561 651 "title" => "Colors", // Title used when prompting for input 562 652 "max" => "1", … … 574 664 array( 575 665 "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside 576 "group" => " test-attachment-single", // The form field name666 "group" => "post-tests-attachment-single", // The form field name 577 667 "title" => "Attachment", // Title used when prompting for input 578 668 "max" => "1", … … 586 676 ); 587 677 588 $this->field( 589 array( 590 "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside 591 "group" => "test-wysiwyg-single", // The form field name 592 "title" => "WYSIWYG", // Title used when prompting for input 593 "max" => "1", 678 679 680 $this->field( 681 array( 682 "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside 683 "group" => "post-tests-date-single", // The form field name 684 "title" => "Date", // Title used when prompting for input 685 "max" => "1", 686 "fields" => array( 687 "value" => array( 688 "type" => "date", 689 "description" => "Date Description" 690 ) 691 ) // end fields 692 ) // end array 693 ); 694 695 $this->field( 696 array( 697 "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside 698 "group" => "post-tests-suggest-post-single", // The form field name 699 "title" => "Suggest Posts", // Title used when prompting for input 700 "max" => "1", 701 "fields" => array( 702 "value" => array( 703 "type" => "suggest", 704 "description" => "Suggest Posts Description", 705 "wp_query" => array("post_type" => "post"), 706 ) 707 ) // end fields 708 ) // end array 709 ); 710 711 $this->field( 712 array( 713 "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside 714 "group" => "post-tests-suggest-pages-single", // The form field name 715 "title" => "Suggest Pages", // Title used when prompting for input 716 "max" => "1", 717 "fields" => array( 718 "value" => array( 719 "type" => "suggest", 720 "description" => "Suggest Pages Description", 721 "wp_query" => array("post_type" => "page"), 722 ) 723 ) // end fields 724 ) // end array 725 ); 726 727 $this->field( 728 array( 729 "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside 730 "group" => "post-tests-suggest-users-single", // The form field name 731 "title" => "Suggest All Users", // Title used when prompting for input 732 "max" => "1", 733 "fields" => array( 734 "value" => array( 735 "type" => "suggest", 736 "description" => "Suggest All Users", 737 "wp_query" => array(), 738 ) 739 ) // end fields 740 ) // end array 741 ); 742 743 $this->field( 744 array( 745 "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside 746 "group" => "post-tests-suggest-subscribers-single", // The form field name 747 "title" => "Suggest Users (Subscriber)", // Title used when prompting for input 748 "max" => "1", 749 "fields" => array( 750 "value" => array( 751 "type" => "suggest", 752 "description" => "Suggest All Subscribers", 753 "wp_query" => array("role" => "subscriber"), 754 ) 755 ) // end fields 756 ) // end array 757 ); 758 759 760 /** 761 * Post Metabox Multiple Fields Test 762 */ 763 764 765 $this->metabox( 766 array( 767 'id' => 'field-post-tests-multi', 768 'title' => 'Field Post Tests (multi)', 769 'post_type' => array('post','page') 770 ) 771 ); 772 773 774 775 $this->field( 776 array( 777 "metabox" => "field-post-tests-multi", // the id of the metabox this field resides inside 778 "group" => "post-tests-checkbox-multi", // The form field name 779 "title" => "Checkbox", // Title used when prompting for input 780 "max" => "5", 781 "fields" => array( 782 "value" => array( 783 "type" => "checkbox", 784 "description" => "Checkbox Description" 785 ) 786 ) // end fields 787 ) // end array 788 ); 789 790 $this->field( 791 array( 792 "metabox" => "field-post-tests-multi", // the id of the metabox this field resides inside 793 "group" => "post-tests-text-multi", // The form field name 794 "title" => "Text", // Title used when prompting for input 795 "max" => "5", 594 796 "fields" => array( 595 797 "value" => array( 596 798 "type" => "text", 597 "description" => "WYSIWYG Description" 598 ) 599 ) // end fields 600 ) // end array 601 ); 602 603 $this->field( 604 array( 605 "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside 606 "group" => "test-date-single", // The form field name 799 "description" => "Text Description", 800 ) 801 ) // end fields 802 ) // end array 803 ); 804 805 $this->field( 806 array( 807 "metabox" => "field-post-tests-multi", // the id of the metabox this field resides inside 808 "group" => "post-tests-textarea-multi", // The form field name 809 "title" => "Textarea", // Title used when prompting for input 810 "max" => "5", 811 "style" => "block", 812 "fields" => array( 813 "value" => array( 814 "type" => "textarea", 815 "description" => "Textarea Description", 816 ) 817 ) // end fields 818 ) // end array 819 ); 820 821 $this->field( 822 array( 823 "metabox" => "field-post-tests-multi", // the id of the metabox this field resides inside 824 "group" => "post-tests-select-multi", // The form field name 825 "title" => "Select", // Title used when prompting for input 826 "max" => "5", 827 "fields" => array( 828 "value" => array( 829 "type" => "select", 830 "description" => "Select Description", 831 "selections" => array("0"=>"0","1"=>"1","2"=>"2") 832 ) 833 ) // end fields 834 ) // end array 835 ); 836 837 838 $this->field( 839 array( 840 "metabox" => "field-post-tests-multi", // the id of the metabox this field resides inside 841 "group" => "post-tests-color-multi", // The form field name 842 "title" => "Colors", // Title used when prompting for input 843 "max" => "5", 844 845 "fields" => array( 846 "value" => array( 847 "type" => "color", 848 "description" => "Color Description", 849 ) 850 ) // end fields 851 ) // end array 852 ); 853 854 $this->field( 855 array( 856 "metabox" => "field-post-tests-multi", // the id of the metabox this field resides inside 857 "group" => "post-tests-attachment-multi", // The form field name 858 "title" => "Attachment", // Title used when prompting for input 859 "max" => "5", 860 "fields" => array( 861 "value" => array( 862 "type" => "attachment", 863 "description" => "Attachment Description" 864 ) 865 ) // end fields 866 ) // end array 867 ); 868 869 870 871 $this->field( 872 array( 873 "metabox" => "field-post-tests-multi", // the id of the metabox this field resides inside 874 "group" => "post-tests-date-multi", // The form field name 607 875 "title" => "Date", // Title used when prompting for input 608 "max" => " 1",609 "fields" => array( 610 "value" => array( 611 "type" => " text",876 "max" => "5", 877 "fields" => array( 878 "value" => array( 879 "type" => "date", 612 880 "description" => "Date Description" 613 881 ) … … 618 886 $this->field( 619 887 array( 620 "metabox" => "field-post-tests- single", // the id of the metabox this field resides inside621 "group" => " test-suggest-post-single", // The form field name888 "metabox" => "field-post-tests-multi", // the id of the metabox this field resides inside 889 "group" => "post-tests-suggest-post-multi", // The form field name 622 890 "title" => "Suggest Posts", // Title used when prompting for input 623 "max" => " 1",891 "max" => "5", 624 892 "fields" => array( 625 893 "value" => array( 626 894 "type" => "suggest", 627 895 "description" => "Suggest Posts Description", 628 " suggestions" => "post",629 ) 630 ) // end fields 631 ) // end array 632 ); 633 634 $this->field( 635 array( 636 "metabox" => "field-post-tests- single", // the id of the metabox this field resides inside637 "group" => " test-suggest-pages-single", // The form field name638 "title" => "Suggest P osts", // Title used when prompting for input639 "max" => " 1",896 "wp_query" => array("post_type" => "post"), 897 ) 898 ) // end fields 899 ) // end array 900 ); 901 902 $this->field( 903 array( 904 "metabox" => "field-post-tests-multi", // the id of the metabox this field resides inside 905 "group" => "post-tests-suggest-pages-multi", // The form field name 906 "title" => "Suggest Pages", // Title used when prompting for input 907 "max" => "5", 640 908 "fields" => array( 641 909 "value" => array( 642 910 "type" => "suggest", 643 911 "description" => "Suggest Pages Description", 644 "suggestions" => "page", 645 ) 646 ) // end fields 647 ) // end array 648 ); 649 650 912 "wp_query" => array("post_type" => "page"), 913 ) 914 ) // end fields 915 ) // end array 916 ); 917 918 $this->field( 919 array( 920 "metabox" => "field-post-tests-multi", // the id of the metabox this field resides inside 921 "group" => "post-tests-suggest-users-multi", // The form field name 922 "title" => "Suggest All Users", // Title used when prompting for input 923 "max" => "5", 924 "fields" => array( 925 "value" => array( 926 "type" => "suggest", 927 "description" => "Suggest All Users", 928 "wp_query" => array(), 929 ) 930 ) // end fields 931 ) // end array 932 ); 933 934 $this->field( 935 array( 936 "metabox" => "field-post-tests-multi", // the id of the metabox this field resides inside 937 "group" => "post-tests-suggest-subscribers-multi", // The form field name 938 "title" => "Suggest Users (Subscriber)", // Title used when prompting for input 939 "max" => "5", 940 "fields" => array( 941 "value" => array( 942 "type" => "suggest", 943 "description" => "Suggest All Subscribers", 944 "wp_query" => array("role" => "subscriber"), 945 ) 946 ) // end fields 947 ) // end array 948 ); 651 949 652 950 } // end function -
diy/trunk/readme.txt
r498186 r500696 3 3 Tags: framework,plugin,custom post types,jquery 4 4 Requires at least: 3.2.1 5 Version: 0.0. 15 Version: 0.0.2 6 6 Tested up to: 3.2.1 7 7 Stable Tag: 0.0.1 … … 12 12 Define an extensible framework for building other plugins. 13 13 See the source of the Test Suite for an example of each of the field definitions. 14 = Diy Homepage = 15 All of the documentation is on github 14 15 = Documentation = 16 All of the documentation is on github https://github.com/onemanonelaptop/diy/wiki 17 16 18 = Status = 17 In development, not considered stable 19 In development, not considered stable https://github.com/onemanonelaptop/diy/issues?sort=created&direction=desc&state=open 18 20 19 21 == Installation == … … 34 36 == Changelog == 35 37 38 = 0.0.2 = 39 * General Cleanup 40 36 41 = 0.0.1 = 37 42 * Alpha Version
Note: See TracChangeset
for help on using the changeset viewer.