Plugin Directory

Changeset 500696


Ignore:
Timestamp:
02/05/2012 06:57:58 PM (14 years ago)
Author:
OneManOneLaptop
Message:
 
Location:
diy/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • diy/trunk/diy.php

    r498186 r500696  
    4242            * The Abstract Diy Class
    4343            *   
    44             * @since    0.1
     44            * @since    0.0.1
    4545            * @access   public
    4646            */
     
    100100                    * @var array Set to true to remove sidebar metaboxes on the options page
    101101                    */
    102                     protected $is_generic = false;
     102                    protected $generic = false;
    103103
    104104                    /**
     
    132132                    protected $diy_url = '';
    133133                   
     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
    134237                   
    135238                    /**
    136239                    * This starts the process of defining the plugin
    137                     * @return void
     240                    * @return void 
    138241                    */
    139242                    public function diy_start() {
     
    144247                        }
    145248
    146                         // generate the options_group var name
     249                        // generate the options_group variable name from the slug
    147250                        if ($this->options_group == '') {
    148251                                $this->options_group = $this->slug;
     
    163266                        $this->diy_url = str_replace(ABSPATH,trailingslashit(get_option( 'siteurl' )),$this->diy_path);
    164267
    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') {
    179287                                // Add the plugins options page
    180288                                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) {
    188293                                add_action('admin_init', array(&$this,'diy_add_predefined_metaboxes') );
     294                            }
    189295                        }
    190296
    191297                        // Setup the ajax callback for autocomplete widget
    192298                        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                     
    195303                        // Setup some query vars to serve javascript and css via a url
    196304                        add_action( 'template_redirect', array( &$this, 'diy_script_server' ));
     
    198306                                         
    199307                    } // end function
    200                    
    201                    
    202                      /**
     308                                   
     309                    /**
    203310                    * Return a link to the admin icon
    204311                    * @param string $hook Current page hook
     
    207314                    function diy_settings_page_icon( $hook ) {
    208315            if ($hook == $this->hook)
    209                 return plugin_dir_url( __FILE__ ).$this->icon;
     316                            return plugin_dir_url( __FILE__ ).$this->icon;
    210317            return $hook;
    211318                    }
    212319       
    213 
    214320                    /**
    215321                    * For each filed defined by the child plugin add it to the appropriate options page/post metabox
     
    226332                        foreach($this->fields as $field) {
    227333                           
    228                             // get the metabox post_types the field is attached to
     334                            // This field is inside a metabox, that metabox may be use on more than one poswt type, so go get the post types
    229335                            $metabox_post_types = $this->diy_get_metabox_post_types($field['metabox']);
    230336
    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
    232338                            if ($metabox_post_types!="") {
    233339                                // If its not an array, then make it one
     
    240346                                }
    241347                            } else { 
     348                                // otherwise add the fields to a settings page
    242349                                add_settings_field(
    243350                                    $field['group'],  // option identifier
     
    251358                                register_setting( $this->options_group, $field['group'], array(&$this,'diy_validate_settings'));
    252359
    253                                 $this->options_meta[ $field['metabox'] ][ $field['group'] ] = $args;
    254 
     360                             
    255361                                // check if this option has previously been created if not apply the defaults
    256362                                if (! get_option( $field['group'] ) ) {
     
    287393                    */
    288394                    function diy_get_metabox_post_types($id) {
    289                         if (!is_array($this->metaboxes)) {
    290                             return '';
    291                         }
    292395                        foreach ($this->metaboxes as $metabox) {
    293396                            if ($metabox['id'] == $id) {
    294                                 return $metabox['post_type'];
     397                                return (isset($metabox['post_type']) ? $metabox['post_type'] : '' );
    295398                            }
    296399                        }
     
    304407                    */
    305408                    function diy_metaboxes() {
    306                         if (!is_array($this->metaboxes)) {
    307                             return;
    308                         }
    309409                        foreach ($this->metaboxes as $metabox) {
    310 
    311                             if ($metabox['post_type'] != '') {
     410                            if (isset($metabox['post_type'])) {
    312411                                // If a post type is set then add the metabox to the post type
    313412                                if (!is_array($metabox['post_type'])) {
     
    318417
    319418                                    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']]
    327426                                    );
    328427                                }     
     
    331430
    332431                                    add_settings_section(
    333                                             $metabox['id'],
    334                                             '',
    335                                             array(&$this, 'section_null'),
    336                                             $this->page
     432                                        $metabox['id'],
     433                                        '',
     434                                        array(&$this, 'section_null'),
     435                                        $this->page
    337436                                    );
    338437                                    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'])
    346445                                    );
    347446
     
    351450
    352451                    /**
    353                     * Vogon constructor
    354                     *
    355                     * @since    0.1
    356                     * @param    string  $file   Contains __FILE__ for the file extending this class
    357                     * @access   public
    358                     * @return   void
    359                     */
    360                     function __construct($file = __FILE__) {
    361                         // Save the filename of the child plugin
    362                         $this->filename = plugin_basename($file);
    363                        
    364                         // Initialise the plugin if the method has been defined in the extended class
    365             if ( is_callable( array($this, 'init') ) ) {
    366                             $this->init();
    367             }   
    368                         // Start the plugin
    369                         $this->diy_start();
    370                        
    371                         // Call the child plugins start method
    372                         if ( is_callable( array($this, 'start') ) ) {
    373                             $this->start();
    374             }   
    375                     } // function
    376 
    377 
    378                     /**
    379452                    *  Serve the CSS or JS when requested via a URL
    380453                    *
    381                     * @since    0.1
     454                    * @since    0.0.1
    382455                    * @access   public
    383456                    * @return   void
    384457                    */
    385458                    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                        }
    403472                    } // function
    404473
    405 
    406474                    /**
    407475                    *  Setup the query variable used to serve js and css data
    408476                    *
    409                     * @since    0.1
     477                    * @since    0.0.1
    410478                    * @param    array   $public_query_vars  An array of the currently registered query var names
    411479                    * @return   array   Query var names array
     
    413481                    */
    414482                    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   
    442487                    /**
    443488                    * Create the Options page for the plugin
    444489                    *
    445                     * @since    0.1
     490                    * @since    0.0.1
    446491                    * @access   public
    447492                    * @return   void
    448493                    */
    449494                    public function diy_add_options_page() {
    450                             // Add a theme page or an option page depending on the diy usage
    451                             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 loads
    459                                     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                        }
    461506                    } // function
    462507
     
    464509                    * Runs only on the plugin page load hook, enables the scripts needed for metaboxes
    465510                    *
    466                     * @since    0.1
    467                     * @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() {
    471516                        wp_enqueue_script('common');
    472517                        wp_enqueue_script('wp-lists');
     
    477522                    * Add a settings link to the plugin list page
    478523                    *
    479                     * @since    0.1
     524                    * @since    0.0.1
    480525                    * @param    string  $file       the filename of the plugin currently being rendered on the installed plugins page
    481526                    * @param    array   $links      an array of the current registered links in html format
     
    497542                    * On the plugin page make sure there are two columns
    498543                    *
    499                     * @since    0.1
     544                    * @since    0.0.1
    500545                    * @access   public
    501546                    * @param   int $columns
     
    503548                    * @return  int number of columns
    504549                    */
    505                     function diy_options_page_columns($columns, $screen) {
     550                    function diy_settings_page_columns($columns, $screen) {
    506551                        if ($screen == $this->page) {
    507552                            $columns[$this->page] = 2;
     
    514559                    * Create the options page form
    515560                    *
    516                     * @since    0.1
     561                    * @since    0.0.1
    517562                    * @access   public
    518563                    * @return   void
     
    559604                    } // function
    560605
    561 
    562 
    563606                    /**
    564607                    * Register some default metaboxes on the plugins options page
    565608                    *
    566                     * @since    0.1
     609                    * @since    0.0.1
    567610                    * @access   public
    568611                    * @todo     This function should use optbox() to define its metaboxes
     
    587630                    } // function
    588631
    589 
    590632                    /**
    591633                    * Meta box for the documention link and the debugging popup
    592634                    *
    593                     * @since    0.1
     635                    * @since    0.0.1
    594636                    * @access   public
    595637                    * @return   void
     
    614656                        print '<li><strong>Diy Path:</strong> ' . $this->diy_path . '</li>';
    615657                        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>';
    618658                        print '</div>';
    619659                    } // function
    620660
    621 
    622661                    /**
    623662                    * Meta box for the bug reporting info
    624663                    *
    625                     * @since    0.1
     664                    * @since    0.0.1
    626665                    * @access   public
    627666                    * @return   void
     
    636675                    * Meta box for displaying social media links
    637676                    *
    638                     * @since    0.1
     677                    * @since    0.0.1
    639678                    * @access   public
    640679                    * @return   void
     
    651690                    * Meta box for displaying plugin rating links
    652691                    *
    653                     * @since    0.1
     692                    * @since    0.0.1
    654693                    * @access   public
    655694                    * @return   void
     
    666705                    * Register the admin scripts
    667706                    *
    668                     * @since    0.1
     707                    * @since    0.0.1
    669708                    * @access   public
    670709                    * @return   void
    671710                    */
    672711                    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'));   
    693743                    } // function
    694744
     
    696746                    * Add custom styles to this plugins options page only
    697747                    *
    698                     * @since    0.1
     748                    * @since    0.0.1
    699749                    * @access   public
    700750                    * @return   void
     
    702752                    function diy_admin_styles() {
    703753
    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
    712761
    713762                    /**
    714763                    * Add scripts globally to all post.php and post-new.php admin screens
    715764                    *
    716                     * @since    0.1
     765                    * @since    0.0.1
    717766                    * @access   public
    718767                    * @return   void
    719768                    */
    720769                    function diy_admin_scripts() {
    721                             // Enqueue our diy specific javascript
    722                             wp_enqueue_script('diy');
    723 
    724                             // Color picker
    725                             wp_enqueue_script('farbtastic'); 
    726 
    727                             // Allow Jquery Chosen
    728                             wp_enqueue_script('suggest');
    729 
    730                             // Allow usage of the google map api
    731                             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');
    732781                    }
    733782
    734783                    /**
    735                     * Define a metabox field and add it to a metabox
     784                    * Define a metabox field, apply the defaults add it to the fields array
    736785                    *
    737786                    * @param    mixed $args array that contains the metabox field definition
    738                     * @since    0.1
     787                    * @since    0.0.1
    739788                    * @access   public
    740789                    * @return   void
    741790                    */ 
    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 );
    744804                    } // end function
    745805
    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
    751810                    * @access   public
    752811                    * @param    array   $args
     
    754813                    */ 
    755814                    function metabox( $args) {
    756                         $this->metaboxes[] = $args;
     815                        $this->metaboxes[] = wp_parse_args( $args, $this->metabox_defaults );
    757816                    } // end function
    758817
     
    760819                    *  If a height is specified return the inline style to set it
    761820                    *
    762                     * @since    0.1
     821                    * @since    0.0.1
    763822                    * @access   public
    764823                    * @param    string  $height  the height in pixels
     
    766825                    */
    767826                    function height($height) {
    768                             return ((!empty($height)) ? ' height:'. $height . 'px;' : '');
     827                        return ((!empty($height)) ? ' height:'. $height . 'px;' : '');
    769828                    } // function
    770829
     
    772831                    * If a width is specified return the inline style to set it
    773832                    *
    774                     * @since    0.1
     833                    * @since    0.0.1
    775834                    * @access   public
    776835                    * @param    string  $width  The width in pixels
     
    778837                    */
    779838                    function width($width) {
    780                             return  ((!empty($width)) ? ' width:'. $width . 'px;' : '');
     839                        return  ((!empty($width)) ? ' width:'. $width . 'px;' : '');
    781840                    } // function
    782841
     
    784843                    * If a description is given then return the html to display it
    785844                    *
    786                     * @since    0.1
     845                    * @since    0.0.1
    787846                    * @param    string $d   The text to show for the description
    788847                    * @access   public
     
    790849                    */
    791850                    function description($d) {
    792                             return ( (!empty($d)) ? '<br />' . '<span class="description">'.$d. '</span>' : '');
     851                        return ( (!empty($d)) ? '<br />' . '<span class="description">'.$d. '</span>' : '');
    793852                    } // function
    794853
     
    796855                    * If any placeholder text is specified then add the html attribute to the element
    797856                    *
    798                     * @since    0.1
     857                    * @since    0.0.1
    799858                    * @param    string  $p  The text to use for the placeholder
    800859                    * @access   public
     
    802861                    */
    803862                    function placeholder($p) {
    804                             return ( (!empty($p)) ? 'placeholder="' . $p . '"' : '');
     863                        return ( (!empty($p)) ? 'placeholder="' . $p . '"' : '');
    805864                    } // function
    806865
     
    808867                    * If any suffix text is specified then add the html right after the field
    809868                    *
    810                     * @since    0.1
     869                    * @since    0.0.1
    811870                    * @param    string  $s  The text to use for the suffix
    812871                    * @access   public
     
    814873                    */
    815874                    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                   
    819902                    /**
    820903                    * Build a text input field widget
    821904                    *
    822                     * @since    0.1
     905                    * @since    0.0.1
    823906                    * @param    array   $args   The width, name, value, placeholder and description of the text field
    824907                    * @access   public
     
    826909                    */
    827910                    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']);
    831914                    } // function
    832915
     
    834917                    * Build a datepicker field widget
    835918                    *
    836                     * @since    0.1
     919                    * @since    0.0.1
    837920                    * @param    array   $args   The width, name, value, placeholder and description of the date field
    838921                    * @access   public
     
    840923                    */
    841924                    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
    851933
    852934                    /**
    853935                    * Build a textarea field widget
    854936                    *
    855                     * @since    0.1
     937                    * @since    0.0.1
    856938                    * @param    array   $args   The width, name, value, placeholder and description of the textarea field
    857939                    * @access   public
     
    859941                    */
    860942                    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']);
    863945                    } // function
    864946
     
    866948                    * Build a checkbox field widget
    867949                    *
    868                     * @since    0.1
     950                    * @since    0.0.1
    869951                    * @param    array   $args   The width, name, value, placeholder and description of the checkbox field
    870952                    * @access   public
     
    872954                    */
    873955                    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                   
    881980                    /**
    882981                    * Build a selectbox field widget
    883982                    *
    884                     * @since    0.1
     983                    * @since    0.0.1
    885984                    * @param    array   $args   The width, name, value, placeholder and description of the text field
    886985                    * @return   void
     
    889988                    function select($args)  {
    890989
    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                   
    9071013                    /**
    9081014                    * Render a google map
    9091015                    *
    910                     * @since    0.1
     1016                    * @since    0.0.1
    9111017                    * @access   public
    9121018                    * @param    array   $args
     
    9161022                            global $post;
    9171023                            // 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>';
    9191025                    } // end function map
    9201026
    921 
    9221027                    /**
    9231028                    * Render a color picker field widget
    9241029                    *
    925                     * @since    0.1
     1030                    * @since    0.0.1
    9261031                    * @param    array   $args
    9271032                    * @access   public
     
    9391044                    * Retrieve the ID number of an image/file asset
    9401045                    *
    941                     * @since    0.1
     1046                    * @since    0.0.1
    9421047                    * @access   public
    9431048                    * @param    string  $image_src
     
    9511056                    }
    9521057
    953 
    9541058                    /**
    9551059                    * Render an attachment field widget
    9561060                    *
    957                     * @since    0.1
     1061                    * @since    0.0.1
    9581062                    * @param    array   $args
    9591063                    * @access   public
     
    9661070
    9671071                            // show a preview
    968                             $this->attachment_preview($args['value']);
     1072                            if ($args['preview']) {
     1073                                $this->attachment_preview($args['value']);
     1074                            }
    9691075                            echo $this->description($args['description']); 
    9701076                    } // function
    9711077
    972 
    9731078                    /**
    9741079                    * Generate or display a thumbnail of the chosen file, needs a good cleanup
    9751080                    *
    976                     * @since    0.1
     1081                    * @since    0.0.1
    9771082                    * @param   string  $original
    9781083                    * @access   public
     
    10041109                    } // end function
    10051110
    1006 
    10071111                    /**
    10081112                    * Given a file return it as a url
    10091113                    *
    1010                     * @since    0.1
     1114                    * @since    0.0.1
    10111115                    * @access   public
    10121116                    * @param    string  $file   a filename
     
    10201124                    * Render a suggest posts field widget
    10211125                    *
    1022                     * @since    0.1
     1126                    * @since    0.0.1
    10231127                    * @access   public
    10241128                    * @param    array  $args  field arguments
     
    10261130                    */     
    10271131                    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)  . "'/>";                   
    10291139                        echo $this->description($args['description']);
     1140                       
    10301141                    } // function
    10311142
     
    10331144                    * Render a suggest user field widget
    10341145                    *
    1035                     * @since    0.1
     1146                    * @since    0.0.1
    10361147                    * @access   public
    10371148                    * @param    array  $args  field arguments
     
    10391150                    */     
    10401151                    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'])  . "'/>";                   
    10421153                        echo $this->description($args['description']);
    10431154                    } // function
     
    10461157                    * Render a suggest users field widget
    10471158                    *
    1048                     * @since    0.1
     1159                    * @since    0.0.1
    10491160                    * @access   public
    10501161                    * @param    array  $args  field arguments
     
    10591170                    * Given an id show it along with the title in the autocmoplete textbox
    10601171                    *
    1061                     * @since    0.1
     1172                    * @since    0.0.1
    10621173                    * @see      suggest
    10631174                    * @param    string  $id   
     
    10651176                    * @access   public
    10661177                    */
    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                        }
    10701186                    }
    10711187
     
    10731189                    * Given an id show it along with the title in the autocmoplete textbox e.g. Title [# 101]
    10741190                    *
    1075                     * @since    0.1
     1191                    * @since    0.0.1
    10761192                    * @access   public
    10771193                    * @param    string  $id     A post_id
     
    10891205                    * Ajax callback function to return list of post types
    10901206                    *
    1091                     * @since    0.1
     1207                    * @since    0.0.1
    10921208                    * @access   public
    10931209                    * @return   void
    10941210                    */
    10951211                    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";
    11061252                            }
    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                    */
    11111280                    function callback($args) {
    11121281                            echo $this->{$args['function']}();
     
    11171286                    * Return a list of posts from a post type
    11181287                    *
    1119                     * @since    0.1
     1288                    * @since    0.0.1
    11201289                    * @access   public
    11211290                    * @param    string  $type   The name of a registered post type
     
    11231292                    */
    11241293                    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
    11351302
    11361303                    /**
    11371304                    *  The Callback function to build a post metabox based on the arguments passed in from add_meta_box()
    11381305                    *
    1139                     * @since    0.1
     1306                    * @since    0.0.1
    11401307                    * @access   public
    11411308                    * @param    array   $data
     
    11441311                    */
    11451312                    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
    11711337                    }
    11721338
     
    11741340                    *  Print a field group
    11751341                    *
    1176                     * @since    0.1
     1342                    * @since    0.0.1
    11771343                    * @access   public
    11781344                    * @param    array   $group
     
    11801346                    * @return   void
    11811347                    */
    1182                     function print_field_group($group,$group_values) {
     1348                    function print_field_group($group,$group_values) { 
    11831349                        // if there are more than one field turn individual field titles on
    11841350                        if (count( $group['fields']) > 1) {$is_group = true;} else {$is_group = false;}
     
    11941360                            print '<ul class="field-group" data-set="' . $counter . '">';
    11951361                            foreach( $group['fields'] as $field_name => $field) {
    1196                                 print '<li>';
     1362   
     1363                                print '<li class="field-' . $field_name . '">';
    11971364                                if ($is_group) { print "<label class='" . ($field['label_style'] == 'block' ? "" : "fl" ) . "' style='" . ($field['label_width'] ? "width:" . $field['label_width'] . "px" : "" ) . "'>" . $field['title'] . "</label>";}
    11981365
     
    12001367                                $field['name'] = "" . $group['group'] . "[" . $counter . "][" . $field_name . "]";
    12011368                                $field['id'] = $group['group'] . "-" . $counter . "-" . $field_name;
     1369                               
     1370                                $field['group'] = $group['group'];
     1371                                $field['field'] = $field_name;
    12021372                               
    12031373                                // Set the current value of the field
     
    12261396
    12271397
    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>"; }
    12291399
    12301400                        print '<div style="clear:both;"></div></div>';
     
    12341404                    *  Save the post meta box field data
    12351405                    *
    1236                     * @since    0.1
     1406                    * @since    0.0.1
    12371407                    * @access   public
    12381408                    * @param    string  $post_id    The post id we are saving
     
    12511421
    12521422                        // 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;
    12561426                        } 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;
    12591429                        }
    12601430                       
    12611431                        // 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']])  ) {
    12631433
    12641434                            // go through each of the registered post metaboxes
     
    12691439                                   
    12701440                                    // 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                                       
    12721447
    12731448                                    // Convert autosuggest value to a post id
     
    13091484                    * Print the form field group on the settings page
    13101485                    *
    1311                     * @since    0.1
     1486                    * @since    0.0.1
    13121487                    * @access   public
    13131488                    * @param    array   $args
     
    13251500                    * Build the meta box content and print the fields
    13261501                    *
    1327                     * @since    0.1
     1502                    * @since    0.0.1
    13281503                    * @access   public
    13291504                    * @param    array   $data
     
    13421517                            do_settings_fields(  $this->page, $args['args']['section'] );
    13431518                        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                        }
    13441526                    } // function
    13451527
     
    13471529                    * Convert all autocomplete fields to a post_id [# ]
    13481530                    *
    1349                     * @since    0.1
     1531                    * @since    0.0.1
    13501532                    * @access   public
    13511533                    * @param    array   $data   the array of options
     
    13691551                                        }
    13701552                                    }
     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                                   
    13711566                                } // end foreach
    13721567                            } // end foreach
     
    13811576                    * The CSS is iself served instead of as separate file to keep the Diy class as a single file
    13821577                    *
    1383                     * @since    0.1
     1578                    * @since    0.0.1
    13841579                    * @access   public
    13851580                    * @return   void
     
    13871582                    function diy_css() {
    13881583                            // 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;}';
    13901585                            print '.field-group-multi .field-group {border-bottom: 1px solid #E3E3E3; margin: 0px 0 10px 0; }';
    13911586                            print '.field-group-sortable .field-group {padding-left:20px; cursor: move; background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAYAAABy6+R8AAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJ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6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfVP1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i/suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUwAADqYAAAOpgAABdvkl/FRgAAAL9JREFUeNp8kiEOhTAQRKcYBJLDoMByAI7AMXoWLkMVsqquboNr1hCC2q8+aYF2zKaZvN3ZtkBG67pKzqtywLZtWbD6Aqy1YGYYY4oTExGRaK2FiMqT4o5N0yT16VdxJO+9EJGEEAAAIQQQkXjvxTl3g+q/NDMXI5/nibZt0fc9VHxb0zShrmtc14VlWTDPc3IexxHDMKjPzMwsWmthZsnuBCDpcBxHUp++yj3svu/3DkmkLygGu657AUWVfsJvAPNNleEaizeIAAAAAElFTkSuQmCC) no-repeat 0px 0px;}';
     
    15181713                            print '.ui-icon-circle-triangle-e {background: transparent url(../../../wp-admin/images/arrows.png) no-repeat 6px -103px;
    15191714                            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+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC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bpSmabJaqdRm3j9yLPlC6IAg885vUhFgEyxFKnop/cw4cQZoNNja9lJ4IABfbPB56dWkz7HlFJN4ClwwCHz5Zt5IngSWFwFOrmkqqn02Rk6JqGPnS68fE0ZOeQSablyJXBjLG8NHBQpLKrHhB6p1pdUIKEXkMw4eEx2Wna+8nW6S56WbIrT/cCawL6nApgkkR4DTdA1dZ3Y6jypb3XRJAomkCCUOZTwFQoogVn8CrYaSHAoBu3qB0XOkhuT09gHFIlCrKn/TYmFBV71raDUd11mvAeUS8DQLzM8BsRjQ30/nWWVjH8dwbLPpeArQagGVMmDTbllA53YgHPrX7PA2skWBjQ1CEET3K4ynwGppqJZVBknEqWtAfC8w91l98SGy3aBu2CqmWlEYr41mXV3BtpSSmQ/AgWFg4r7qwp27wOwnmrhfgJ+zW5CNuqPqR0Vai2vXO3Yncv7ePURCWRrt9rFUXkzMxQyG3K60VpZQWf4y3rVg5VwFnUI+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+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6e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M+z8P7PczL6LqO/zksve5OMIAVUCyArqG+hq+/19Z06UplebWH9hNSZG3RN/slnNx9y1iwYysQUAPejesHBvSoBLDbuAe3+x89vthxq7G82EbQ3GGXq5HksT7vwtTIhx9PnyhK7jX79wQF4shxxSMPh5+97PZ0IZVbQTwjQdMVg2S12MCxPK733mysq2p49XxqzKLk9idpz0IvxYa64b7RiU5PM0IpL4RsAFJeQCovIa2kkZDD2Ir+xK74GV0eDyiXakwDN18/0tPS6w6l5ohQIgYxJPNJpJQUwulthBMRVBb1ICpI8Me/obf1vJtqTIPTJ9uvMWwcYlZAQNhCKCpgL7mDoORHLCGgxTUAl7MEfJGL4AEwbMLQmAZ2TmtMKwkExQBKmVr0Nd+AQ6uCJMi40HQVfEkG/sg0FkLT0Kw28rSooTFDlOm4+RREOYMSRwIObhX9p9qRVztIuBLWg8uY3VyAs+I49lUFUlYyNKZBTAz7hHSoSrVmMReZRyYfxNCZTiK2Y2V7FTMbiyjjq0igElQ9BzujGhrTYHcv8EmUQt2qRYPVXob5WAD7izLqSssws/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','');
    15211731                    } // end function
    15221732
     
    15271737                    * The JS is self served instead of as separate file to keep the diy as a single file
    15281738                    *
    1529                     * @since    0.1
     1739                    * @since    0.0.1
    15301740                    * @access   public
    15311741                    * @return   void
     
    15371747
    15381748                            // Apply sorting to DOM elements where class is field-group-sortable
    1539                             print '    $(".field-group-sortable").sortable({
     1749                            print '    jQuery(".field-group-sortable").sortable({
    15401750                                            update: function(event,ui) {               
    15411751                                                reset_field_order(this);
     
    15621772                                                    });
    15631773                                                    // 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)); }
    15651775                                             });
    15661776                                           
     
    15701780                                            // Add the add another button if needed
    15711781                                            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>")
    15731783                                            }
    15741784
     
    15761786                           
    15771787                            // 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) {
    15791789                                            event.preventDefault();
    15801790
    15811791                                            // Save a reference to the outer wrapper   
    1582                                             var wrapper = $(this).closest(".field-group-wrapper");     
     1792                                            var wrapper = jQuery(this).closest(".field-group-wrapper");     
    15831793
    15841794                                            // remove the one we want to delete
    1585                                             $(this).closest(".field-group").remove();
     1795                                            jQuery(this).closest(".field-group").remove();
    15861796
    15871797                                            // Reset the field ordering
     
    15901800
    15911801                            // 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) {
    15931803                                    event.preventDefault();
    1594 
    1595                                     var wrapper = $(this).closest(".field-group-wrapper");
     1804                                 
     1805                                    var wrapper = jQuery(this).closest(".field-group-wrapper");
    15961806
    15971807                                    var newgroup = jQuery(wrapper).find(".field-group:first").clone();
    15981808
    15991809                                    // 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);
    16031812                                    newgroup.find(".field").each(function (index) {
    16041813
    16051814                                            // 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",""); }
    16071816                                           
    16081817                                            // 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                                            );
    16101824                                           
    16111825                                    });
    16121826
    1613                                     newgroup.insertBefore($(this));
     1827                                    newgroup.insertBefore(jQuery(this));
    16141828                                     
    16151829                                    // Reset the field ordering
     
    16371851                                    var imgurl, aurl;
    16381852                                    if (jQuery(".attachment.active").length > 0) {
    1639                                     console.log(html);
     1853                                   
    16401854                                            imgurl = jQuery("img",html).attr("src");
    16411855                                            aurl = jQuery("a","<div>" + html + "</div>").attr("href");
     
    16601874                            print '         function () { ';
    16611875                            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") + ""';
    16631877                            print '             );';
    16641878                            print '             jQuery(this).addClass("suggested");';
     
    17141928
    17151929                                    // for each div with the class of gmap
    1716                                     $(".gmap").each(function(index){
     1930                                    jQuery(".gmap").each(function(index){
    17171931                                            var map = [];
    17181932
    17191933                                            // 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();
    17221936
    17231937                                            // Setup the map center/marker location
     
    17261940                                            // define the map options
    17271941                                            var options = {
    1728                                                     zoom: $(this).data("zoom"),
     1942                                                    zoom: jQuery(this).data("zoom"),
    17291943                                                    center: latlng,
    17301944                                                    mapTypeId: google.maps.MapTypeId.ROADMAP,
     
    17341948
    17351949
    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);
    17371951
    17381952                                            // stick the map marker on the map
     
    17451959                                            // add the map clickerooner
    17461960
    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");
    17491963
    17501964                                            google.maps.event.addListener(map[index],"click", function(location) {
     
    17731987
    17741988                                    });';
    1775 
     1989                            // Add any plugin defined admin js
     1990                            print apply_filters('diy_js','');
    17761991                            // end closure
    17771992                            print '});';
     1993                           
     1994                           
    17781995
    17791996                    } // end function
    17801997                } // end class definition
    17811998
    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
    17842008                    $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];
    17882012                    } else {
    1789                             return '';
     2013                        // return an empty string like get_post_meta does if the key is not set
     2014                        return '';
    17902015                    }
    17912016                } // end function
    17922017
    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                */ 
    17942025                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                    }
    18032036                } // end function
    18042037                   
  • diy/trunk/diytests.php

    r498144 r500696  
    2626*/
    2727
     28// Check if the DIY framework plugin is installed and prompt if necessary
     29if (!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
    2833add_action( 'diy_init', 'testdiy_init' );
     34
    2935/**
    3036 * Define the entire functionality inside the diy_init action which only called
     
    95101                    );
    96102                   
    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);
    112120                   
    113121                    // Textarea field test
     
    138146                                    "type" => "select",
    139147                                    "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",
    140165                                    "selections" => array("0"=>"0","1"=>"1","2"=>"2")
    141166                                )
     
    222247                                    "type" => "suggest",
    223248                                    "description" => "Suggest Posts Description",
    224                                     "suggestions" => "post",
     249                                    "wp_query" => array("post_type" => "post"),
    225250                                )
    226251                            ) // end fields
     
    233258                            "metabox" => "field-tests-single", // the id of the metabox this field resides inside
    234259                            "group" => "test-suggest-pages-single", // The form field name
    235                             "title" => "Suggest Posts", // Title used when prompting for input
     260                            "title" => "Suggest Pages", // Title used when prompting for input
    236261                            "max" => "1",
    237262                            "fields" => array(
     
    239264                                    "type" => "suggest",
    240265                                    "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                   
    246307                   
    247308                    // Suggest location field test
     
    290351            ) // end array
    291352                             );
     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                    );
    292370                   
    293371                    // MULTI FIELD TESTS
     
    385463                                    "type" => "select",
    386464                                    "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",
    387482                                    "selections" => array("0"=>"0","1"=>"1","2"=>"2")
    388483                                )
     
    467562                                    "type" => "suggest",
    468563                                    "description" => "Suggest Posts Description",
    469                                     "suggestions" => "post",
     564                                    "wp_query" => array("post_type" => "post"),
    470565                                )
    471566                            ) // end fields
     
    486581                    );
    487582                   
    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                 
    495584                       
    496585                    $this->field(
    497586                        array(
    498587                            "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside
    499                             "group" => "test-checkbox-single", // The form field name
     588                            "group" => "post-tests-checkbox-single", // The form field name
    500589                            "title" => "Checkbox", // Title used when prompting for input
    501590                            "max" => "1",
     
    512601                        array(
    513602                            "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside
    514                             "group" => "test-text-single", // The form field name
     603                            "group" => "post-tests-text-single", // The form field name
    515604                            "title" => "Text", // Title used when prompting for input
    516605                            "max" => "1",
     
    527616                        array(
    528617                            "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside
    529                             "group" => "test-textarea-single", // The form field name
     618                            "group" => "post-tests-textarea-single", // The form field name
    530619                            "title" => "Textarea", // Title used when prompting for input
    531620                            "max" => "1",
     621                            "style" => "block",
    532622                            "fields" => array(
    533623                                "value" => array(
     
    542632                        array(
    543633                            "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside
    544                             "group" => "test-select-single", // The form field name
     634                            "group" => "post-tests-select-single", // The form field name
    545635                            "title" => "Select", // Title used when prompting for input
    546636                            "max" => "1",
     
    554644                        ) // end array
    555645                    );
    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 name
     646
     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
    561651                            "title" => "Colors", // Title used when prompting for input
    562652                            "max" => "1",
     
    574664                        array(
    575665                            "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside
    576                             "group" => "test-attachment-single", // The form field name
     666                            "group" => "post-tests-attachment-single", // The form field name
    577667                            "title" => "Attachment", // Title used when prompting for input
    578668                            "max" => "1",
     
    586676                    );
    587677                   
    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",
    594796                            "fields" => array(
    595797                                "value" => array(
    596798                                    "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
    607875                            "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",
    612880                                    "description" => "Date Description"
    613881                                )
     
    618886                    $this->field(
    619887                        array(
    620                             "metabox" => "field-post-tests-single", // the id of the metabox this field resides inside
    621                             "group" => "test-suggest-post-single", // The form field name
     888                            "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
    622890                            "title" => "Suggest Posts", // Title used when prompting for input
    623                             "max" => "1",
     891                            "max" => "5",
    624892                            "fields" => array(
    625893                                "value" => array(
    626894                                    "type" => "suggest",
    627895                                    "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 inside
    637                             "group" => "test-suggest-pages-single", // The form field name
    638                             "title" => "Suggest Posts", // Title used when prompting for input
    639                             "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",
    640908                            "fields" => array(
    641909                                "value" => array(
    642910                                    "type" => "suggest",
    643911                                    "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                    );
    651949
    652950                } // end function
  • diy/trunk/readme.txt

    r498186 r500696  
    33Tags: framework,plugin,custom post types,jquery
    44Requires at least: 3.2.1
    5 Version: 0.0.1
     5Version: 0.0.2
    66Tested up to: 3.2.1
    77Stable Tag: 0.0.1
     
    1212Define an extensible framework for building other plugins.
    1313See 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 =
     16All of the documentation is on github https://github.com/onemanonelaptop/diy/wiki
     17
    1618= Status =
    17 In development, not considered stable
     19In development, not considered stable https://github.com/onemanonelaptop/diy/issues?sort=created&direction=desc&state=open
    1820
    1921== Installation ==
     
    3436== Changelog ==
    3537
     38= 0.0.2 =
     39* General Cleanup
     40
    3641= 0.0.1 =
    3742* Alpha Version
Note: See TracChangeset for help on using the changeset viewer.