Plugin Directory

Changeset 1467493


Ignore:
Timestamp:
08/04/2016 08:36:08 AM (9 years ago)
Author:
rootabout
Message:

update with select users option functionality and a saving bug

Location:
admin-builder/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • admin-builder/trunk/admin_builder.php

    r1460931 r1467493  
    44  Plugin URI: http://admin-builder.com
    55  Description: A plugin that generates admin panel pages & posts,sidebars,custom admin pages with tabs, custom post types, rest routes, meta boxes and fields (with unlimited textbox, textarea, checkbox, custom select (dropdown box), datepicker, timepicker, colorpicker, upload media fields, with configurable options) Based on what's exported from http://admin-builder.com
    6   Version: 1.1.6
     6  Version: 1.1.7
    77  Author: rootabout
    88  Author URI: http://admin-builder.com
  • admin-builder/trunk/inc/abFields.php

    r1452899 r1467493  
    4646          }
    4747          if (isset($post->ID)) {
     48
    4849              $fieldValue = get_post_meta($post->ID, $fieldName, true);
    4950          }
     
    170171              $selected = selected($post->ID, $fieldValue, false) ? selected($post->ID, $fieldValue, false) : '';
    171172              //set the options
    172               $fieldHTML .= '<option  '.$selected.' value="'.$post->ID.'" >'.$post->post_title.'</option>';
     173              $fieldHTML .= '<option  '.$selected.' value="'.$post->ID.'" >'.$post->post_title.$fieldValue.'</option>';
     174            }
     175
     176            break;
     177            case 'users':
     178            $argsx = array();
     179              $customList = get_users($argsx);
     180            //lines into array
     181            foreach ($customList as $usr) {
     182                //comma separated string into array
     183              $selected = selected($usr->ID, $fieldValue, false) ? selected($usr->ID, $fieldValue, false) : '';
     184              //set the options
     185              $fieldHTML .= '<option  '.$selected.' value="'.$usr->ID.'" >'.$usr->user_login.'</option>';
    173186            }
    174187
     
    236249          // $sGeneral->showArr($fieldValue);
    237250
    238           $oArr = (isset($field['oArr']))?$field['oArr']:array();
     251          $oArr = (isset($field['oArr'])) ? $field['oArr'] : array();
    239252          $fieldHTML .= '<div class="hidden tbdContent">';
    240253          $fieldHTML .= '<div class="groupContainer">';
    241254          $fieldHTML .= '<button type="button" class="btn btn-primary close">X</button>';
    242255          foreach ($oArr as $key) {
    243             $fieldHTML .= $this->dtGenerate($key->label,$fieldName,null,null,$key->value);
     256              $fieldHTML .= $this->dtGenerate($key->label, $fieldName, null, null, $key->value);
    244257          }
    245258          $fieldHTML .= '</div>';
     
    250263          // $sGeneral->showArr($fieldValue);
    251264
    252           if(is_array($fieldValue)){
    253           //
    254           $i=0;
    255 
    256             foreach ($fieldValue as $fv) {
    257               $fieldHTML .= '<div class="groupContainer">';
    258               $fieldHTML .= '<button type="button" class="btn btn-primary close">X</button>';
    259               foreach ($oArr as $key=>$val) {
    260                 $fieldValue = (isset($fv[$val->value]))?$fv[$val->value]:'';
    261                 $fieldHTML .= $this->dtGenerate($val->label,$fieldName,$fv[$val->value],$i,$val->value);
     265          if (is_array($fieldValue)) {
     266              //
     267          $i = 0;
     268
     269              foreach ($fieldValue as $fv) {
     270                  $fieldHTML .= '<div class="groupContainer">';
     271                  $fieldHTML .= '<button type="button" class="btn btn-primary close">X</button>';
     272                  foreach ($oArr as $key => $val) {
     273                      $fieldValue = (isset($fv[$val->value])) ? $fv[$val->value] : '';
     274                      $fieldHTML .= $this->dtGenerate($val->label, $fieldName, $fv[$val->value], $i, $val->value);
     275                  }
     276                  $fieldHTML .= '</div>';
     277                  ++$i;
    262278              }
    263               $fieldHTML .= '</div>';
    264               $i++;
    265             }
    266279          }
    267280
     
    287300      }
    288301      //dynamic textbox generate
    289       private function dtGenerate($label,$name,$value,$index=null,$attr=null){
    290         $arrName = $name;
    291         $origNameStr = 'origName="'.$name.'" ';
    292         if($index!== null && !empty($attr) && !empty($attr)){
    293           $arrName = $name.'['.$index.']['.$attr.']';
    294         }
    295 
    296         $attrStr = '';
    297         if($attr!=null && !empty($attr)){
    298           $attrStr = 'dtArrName="'.$attr.'" ';
    299         }
    300         $fieldHTML = '<div class="form-group">';
    301         $fieldHTML .= '<label for="'.$name.'">'.$label.'</label>';
    302         $fieldHTML .= '<input type="text" name="'.$arrName.'" '.$origNameStr.'  class="form-control" '.$attrStr.' placeholder="Please enter '.$label.'" value="'.$value.'">';
    303         $fieldHTML .= '</div>';
    304         return $fieldHTML;
     302      private function dtGenerate($label, $name, $value, $index = null, $attr = null)
     303      {
     304          $arrName = $name;
     305          $origNameStr = 'origName="'.$name.'" ';
     306          if ($index !== null && !empty($attr) && !empty($attr)) {
     307              $arrName = $name.'['.$index.']['.$attr.']';
     308          }
     309
     310          $attrStr = '';
     311          if ($attr != null && !empty($attr)) {
     312              $attrStr = 'dtArrName="'.$attr.'" ';
     313          }
     314          $fieldHTML = '<div class="form-group">';
     315          $fieldHTML .= '<label for="'.$name.'">'.$label.'</label>';
     316          $fieldHTML .= '<input type="text" name="'.$arrName.'" '.$origNameStr.'  class="form-control" '.$attrStr.' placeholder="Please enter '.$label.'" value="'.$value.'">';
     317          $fieldHTML .= '</div>';
     318
     319          return $fieldHTML;
    305320      }
    306321    }
  • admin-builder/trunk/inc/abMeta.php

    r1452899 r1467493  
    6262                    'priority' => $priority,
    6363                );
    64               }
     64            }
    6565            }
    6666
     
    8181            if (!empty($metaArr)) {
    8282                foreach ($metaArr as $count => $box) {
    83                   $name = $box['name'] ? $box['name'] : 'defName';
     83                    $name = $box['name'] ? $box['name'] : 'defName';
    8484                    $type = $box['type'] ? $box['type'] : 'post';
    8585                    $cpt_name = 'post';
     
    108108    public function save_metaBox_fields($post_id, $post)
    109109    {
    110         $metaArr = $this->gametaboxesArr;
    111         foreach ($metaArr as $mboxKey => $mboxValue) {
    112             switch ($mboxValue['type']) {
    113               //save meta if post, page, cpt
    114             case 'post':
    115             case 'page':
    116             case 'cpt':
    117             /* Verify the nonce before proceeding. */
    118             if (!isset($_POST['aB_nounce_'.$mboxValue['name']]) || !wp_verify_nonce($_POST['aB_nounce_'.$mboxValue['name']], basename(__FILE__))) {
    119                 return $post_id;
    120             }
    121 
    122             /* Get the post type object. */
    123             $post_type = get_post_type_object($post->post_type);
    124             /* Check if the current user has permission to edit the post. */
    125             if (!current_user_can($post_type->cap->edit_post, $post_id)) {
    126                 return $post_id;
    127             }
    128             foreach ($mboxValue['fields'] as $key => $field) {
    129 
    130                 //field name
    131                 $fieldName = 'abMB_'.$mboxValue['name'].$field['name'];
    132 
    133                 // set the new value to a variable
    134                 $new_meta_value = (isset($_POST[$fieldName]) ? $_POST[$fieldName] : '0');
    135                 # code...
    136                 /* Get the meta key. */
    137                 $meta_key = $fieldName;
    138 
    139                 /* Get the meta value of the custom field key. */
    140                 $meta_value = get_post_meta($post_id, $meta_key, true);
    141                 if(is_array($new_meta_value)){
    142                   $tempNewMetaValue = array();
    143                   foreach ($new_meta_value as $key => $value) {
    144                     $tempNewMetaValue[]=$value;
    145                   }
    146                   $new_meta_value = $tempNewMetaValue;
     110      $metaArr = $this->gametaboxesArr;
     111      foreach ($metaArr as $mboxKey => $mboxValue) {
     112          switch ($mboxValue['type']) {
     113                  //save meta if post, page, cpt
     114              case 'post':
     115              case 'page':
     116              case 'cpt':
     117                  /* Verify the nonce before proceeding. */
     118                if (!isset($_POST['aB_nounce_'.$mboxValue['name']]) || !wp_verify_nonce($_POST['aB_nounce_'.$mboxValue['name']], basename(__FILE__))) {
     119                    continue;
    147120                }
    148121
    149                 /* If a new meta value was added and there was no previous value, add it. */
    150                 if ($new_meta_value !== $meta_value) {
    151                     update_post_meta($post_id, $meta_key, $new_meta_value);
    152                 } /* If there is no new meta value but an old value exists, delete it. */
    153                 elseif ('' == $new_meta_value && $meta_value) {
    154                     delete_post_meta($post_id, $meta_key, $meta_value);
    155                 }
    156             }
    157         break;
    158         //don't try to save meta if anything else
    159         default:
    160           continue;
    161         break;
    162       }
     122                  /* Get the post type object. */
     123                  $post_type = get_post_type_object($post->post_type);
     124                  /* Check if the current user has permission to edit the post. */
     125                  if (!current_user_can($post_type->cap->edit_post, $post_id)) {
     126                      return $post_id;
     127                  }
     128                  foreach ($mboxValue['fields'] as $key => $field) {
     129
     130                      //field name
     131                      $fieldName = 'abMB_'.$mboxValue['name'].$field['name'];
     132
     133
     134                      // set the new value to a variable
     135                      $new_meta_value = (isset($_POST[$fieldName]) ? $_POST[$fieldName] : '0');
     136                      # code...
     137                      /* Get the meta key. */
     138                      $meta_key = $fieldName;
     139
     140                      /* Get the meta value of the custom field key. */
     141                      $meta_value = get_post_meta($post_id, $meta_key, true);
     142
     143                      if (is_array($new_meta_value)) {
     144                          $tempNewMetaValue = array();
     145                          foreach ($new_meta_value as $key => $value) {
     146                              $tempNewMetaValue[] = $value;
     147                          }
     148
     149                          $new_meta_value = $tempNewMetaValue;
     150                      }
     151
     152                      /* If a new meta value was added and there was no previous value, add it. */
     153                      if ($new_meta_value !== $meta_value) {
     154                          update_post_meta($post_id, $meta_key, $new_meta_value);
     155                      } /* If there is no new meta value but an old value exists, delete it. */
     156                      elseif ('' == $new_meta_value && $meta_value) {
     157                          delete_post_meta($post_id, $meta_key, $meta_value);
     158                      }
     159                  }
     160            break;
     161            //don't try to save meta if anything else
     162            default:
     163              continue;
     164            break;
     165          }
    163166        }
    164167    }
  • admin-builder/trunk/readme.txt

    r1460931 r1467493  
    44Tags: meta, fields, auto, easy, fast, develop, developers, RAD, build, code, unlimited, service, field
    55Requires at least: 4.0
    6 Tested up to: 4.5
    7 Stable tag: 1.1.6
     6Tested up to: 4.5.3
     7Stable tag: 1.1.7
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    172172Fixed a bug in the routes functionality where post was not being generated, just GET
    173173
     174= 1.1.6 =
     175Fixed a saving bug, added users functionality for select box.
     176
    174177== Arbitrary section ==
    175178
Note: See TracChangeset for help on using the changeset viewer.