Exemplo n.º 1
0
 private static function setMeta($options)
 {
     if (empty($options['id'])) {
         throw new Exception('AeriaUserMeta: You must define a user meta id.', 1);
     }
     if (empty($options['type'])) {
         throw new Exception('AeriaUserMeta: You must define a user meta type.', 1);
     }
     if (!in_array($options['type'], static::$type)) {
         throw new Exception("AeriaUserMeta: The " . $options['type'] . " type isn't supported.", 1);
     }
     $options = array_merge_replace(array('label' => '', 'title' => 'Campi aggiuntivi'), $options);
     $saveMeta = function ($user_id) use($options) {
         global $pagenow;
         if ($pagenow !== 'profile.php' && (!current_user_can('edit_user', $user_id) && $pagenow === 'user-edit.php' or !current_user_can('create_users', $user_id) && $pagenow === 'user-new.php')) {
             return false;
         }
         update_user_meta($user_id, $options['id'], $_POST[$options['id']]);
     };
     $metaFields = function ($user) use($options) {
         if (!current_user_can('read')) {
             return false;
         }
         if (!self::$showedTitle) {
             echo '<h3>', $options['title'], '</h3>';
             self::$showedTitle = true;
         }
         AeriaForm::create(['action' => 'hack', 'type' => 'wordpress', 'startForm' => '', 'endForm' => ''])->setFields(['id' => $options['id'], 'name' => $options['id'], 'label' => $options['label'], 'type' => $options['type'], 'other' => 'class="regular-text"', 'value' => esc_attr(get_the_author_meta($options['id'], $user->ID))])->getForm();
     };
     foreach (static::$saveHook as $value) {
         add_action($value, $saveMeta, 1);
     }
     foreach (static::$showHook as $value) {
         add_action($value, $metaFields, 1);
     }
 }
Exemplo n.º 2
0
    {
        return $this->getElement($point, $addTab, 'before', $param);
    }
    public function getAfter($point, $addTab = NULL, $param = [])
    {
        return $this->getElement($point, $addTab, 'after', $param);
    }
    /**
     * Utils
     */
    /**
     * @param  array   $array        
     * @param  integer $key          
     * @param  boolean $triggerError 
     * @param  string  $errorMessage 
     * @return bool/error()            
     */
    private static function validateArrayKey($array, $key = 0, $triggerError = true, $errorMessage = NULL)
    {
        if (!isset($array[$key]) || empty($array[$key])) {
            if ($triggerError) {
                throw new Exception('AeriaForm: ' . $errorMessage, 1);
            }
            return false;
        } else {
            return true;
        }
    }
}
AeriaForm::setFormType(['wordpress' => ['before' => ['form' => '', 'innerForm' => '<table class="form-table">', 'field' => '<tr>', 'label' => '<th scope="row">', 'input' => '<td>'], 'after' => ['form' => '', 'innerForm' => '</table>', 'field' => '</tr>', 'label' => '</th>', 'input' => '</td>']], 'bootstrap' => ['before' => ['form' => '<div class="row">', 'innerForm' => '', 'field' => '<div class="form-group">', 'label' => '', 'input' => ''], 'after' => ['form' => '</div>', 'innerForm' => '', 'field' => '</div>', 'label' => '', 'input' => '']]]);