/**
  * @see action admin_bar_menu
  * @param $wp_admin_bar
  */
 public function admin_bar_menu($wp_admin_bar)
 {
     // Check this haven't called more than once
     if ($this->done) {
         return;
     }
     /**
      * Filter to disable the Toolset Admin Bar menu
      *
      * Used to disable the Admin Bar Menu when the 'show_admin_bar_shortcut' entry on the 'toolset_options' option has an 'off' value
      * It is up to the plugins to produce a GUI for setting that value
      *
      * @since 1.7
      */
     if (apply_filters('toolset_filter_toolset_admin_bar_menu_disable', false)) {
         return;
     }
     if ($this->get_default_plugin() && $this->has_capatibilities() && $this->is_assignable()) {
         //
         //  We create a Toolset menu and a child submenu.
         //  Clicking the parent achieves the same result than clicking the child
         //  Maybe we add extra menu options in the future
         //
         //  (Icon) Design with Toolset < $href >
         //   |
         //   +- $title < $href >
         //
         $menu_data = $this->get_menu_data();
         if (empty($menu_data)) {
             // If no menu is available, then don't render menu
             return;
         }
         list($title, $href) = $menu_data;
         $args = array('id' => 'toolset_admin_bar_menu', 'title' => __('Design with Toolset', 'wpv-views'), 'href' => $href, 'meta' => array('class' => 'toolset-edit-link'));
         $wp_admin_bar->add_node($args);
         $args = array('parent' => 'toolset_admin_bar_menu', 'id' => 'toolset_design_this_item', 'title' => $title, 'href' => $href);
         $wp_admin_bar->add_node($args);
         /**
          * Collect an array of menu item definitions and create submenu items in the Toolset Admin bar menu.
          *
          * @param array $menu_item_definitions array()
          * @param string $context Current context - see Toolset_Admin_Bar_Menu::get_context().
          * @param int|bool $post_id Id of the currently displayed post or false if not applicable.
          * @return array Array of menu item definition. Each definition is an array with following keys:
          *     string $title Title of the menu item.
          *     string $edit_url URL of the menu item.
          *     string $menu_id Slug of the item. Should be unique.
          *     If some of the arguments is missing or empty after sanitizing, the menu item will be skipped.
          * @since 1.7
          */
         $menu_item_definitions = apply_filters('toolset_filter_toolset_admin_bar_menu_insert', array(), $this->get_context(), get_the_ID());
         foreach ($menu_item_definitions as $menu_row) {
             $title = sanitize_text_field(toolset_getarr($menu_row, 'title', null));
             $edit_url = esc_url_raw(toolset_getarr($menu_row, 'href', null));
             $menu_id = esc_attr(toolset_getarr($menu_row, 'menu_id', null));
             if (!empty($title) && !empty($edit_url) && !empty($menu_id)) {
                 $wp_admin_bar->add_node(array('parent' => 'toolset_admin_bar_menu', 'id' => $menu_id, 'title' => $title, 'href' => $edit_url));
             }
         }
         $settings_href = $this->get_settings_href();
         $args = array('parent' => 'toolset_admin_bar_menu', 'id' => 'toolset_remove_this_menu', 'title' => __('Remove this menu', 'wpv-views'), 'href' => $settings_href);
         $wp_admin_bar->add_node($args);
         $this->done = true;
     }
 }
Exemplo n.º 2
0
/**
 * Safely retrieve a key from $_GET variable.
 *
 * This is a wrapper for toolset_getarr(). See that for more information.
 *
 * @param string $key See toolset_getarr().
 * @param mixed $default See toolset_getarr().
 * @param null|array $valid See toolset_getarr().
 *
 * @return mixed See wpv_getarr().
 *
 * @since 1.7
 */
function toolset_getget($key, $default = '', $valid = null)
{
    return toolset_getarr($_GET, $key, $default, $valid);
}
Exemplo n.º 3
0
/**
 * Calls view function for specific usermeta field type.
 *
 * @param $field_id
 * @param array $params (additional attributes: user_id, user_name, user_is_author, user_current)
 * @param null $content
 * @param string $code
 *
 * @return string|void
 * @since unknown
 */
function types_render_usermeta($field_id, $params, $content = null, $code = '')
{
    global $wpcf, $post, $wpdb, $WP_Views;
    $current_user = wp_get_current_user();
    $current_user_id = $current_user->ID;
    // Set post ID
    // user_id, user_name, user_is_author, user_current
    if (is_object($post)) {
        $post_id = $post->ID;
    } else {
        $post_id = 0;
    }
    if (isset($params['post_id']) && !empty($params['post_id'])) {
        $post_id = $params['post_id'];
    }
    // Get User id from views loop
    if (isset($WP_Views->users_data['term']->ID) && !empty($WP_Views->users_data['term']->ID)) {
        $params['user_id'] = $WP_Views->users_data['term']->ID;
    }
    //Get user By ID
    if (isset($params['user_id'])) {
        $user_id = $params['user_id'];
    } else {
        if (isset($params['user_name'])) {
            //Get user by login
            $user_id = $wpdb->get_var($wpdb->prepare("SELECT * FROM " . $wpdb->users . " WHERE user_login = %s", $params['user_name']));
        } else {
            if (isset($params['user_is_author'])) {
                //Get Post author
                $user_id = $post->post_author;
            } else {
                if (isset($params['user_current'])) {
                    //Get current logged user
                    $user_id = $current_user_id;
                } else {
                    //If empty get post author, if no post, return empty
                    if (!empty($post_id)) {
                        $user_id = $post->post_author;
                    } else {
                        return '';
                    }
                }
            }
        }
    }
    if (empty($user_id)) {
        return '';
    }
    // Get field
    $field = types_get_field($field_id, 'usermeta');
    // If field not found return empty string
    if (empty($field)) {
        // Log
        if (!function_exists('wplogger')) {
            require_once WPCF_EMBEDDED_TOOLSET_ABSPATH . '/toolset-common/wplogger.php';
        }
        global $wplogger;
        $wplogger->log('types_render_field call for missing field \'' . $field_id . '\'', WPLOG_DEBUG);
        return '';
    }
    if (types_is_repetitive($field)) {
        $wpcf->usermeta_repeater->set($user_id, $field);
        $_meta = $wpcf->usermeta_repeater->_get_meta();
        $meta = toolset_getarr($_meta, 'custom_order', '');
        // Sometimes if meta is empty - array(0 => '') is returned
        if (count($meta) == 1 && reset($meta) == '') {
            return '';
        }
        if (!empty($meta)) {
            $output = '';
            if (isset($params['index'])) {
                $index = $params['index'];
            } else {
                $index = '';
            }
            // Allow wpv-for-each shortcode to set the index
            $index = apply_filters('wpv-for-each-index', $index);
            if ($index === '') {
                $output = array();
                foreach ($meta as $temp_key => $temp_value) {
                    $params['field_value'] = $temp_value;
                    $temp_output = types_render_field_single($field, $params, $content, $code, $temp_key);
                    if (!Toolset_Utils::is_field_value_truly_empty($temp_output)) {
                        $output[] = $temp_output;
                    }
                }
                if (!empty($output) && isset($params['separator'])) {
                    $output = implode(html_entity_decode($params['separator']), $output);
                } else {
                    if (!empty($output)) {
                        $output = implode('', $output);
                    } else {
                        return '';
                    }
                }
            } else {
                // Make sure indexed right
                $_index = 0;
                foreach ($meta as $temp_key => $temp_value) {
                    if ($_index == $index) {
                        $params['field_value'] = $temp_value;
                        $output = types_render_field_single($field, $params, $content, $code, $temp_key);
                    }
                    $_index++;
                }
            }
            $html = $output;
        } else {
            return '';
        }
    } else {
        $params['field_value'] = get_user_meta($user_id, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
        if ($params['field_value'] == '' && $field['type'] != 'checkbox') {
            return '';
        }
        $html = types_render_field_single($field, $params, $content, $code);
    }
    // API filter
    $wpcf->usermeta_field->set($user_id, $field);
    return $wpcf->usermeta_field->html($html, $params);
}
 /**
  * Determine whether the actual field value needs to be replaced by a default one.
  *
  * @param mixed $actual_value
  * @return string|mixed The actual value or the default one if the actual one is empty.
  * @since 2.2.3
  */
 private function maybe_apply_default_value($actual_value)
 {
     // empty( "0" ) == true but we don't want that
     $is_default_value_needed = empty($actual_value) && !is_numeric($actual_value);
     if ($is_default_value_needed) {
         $default_value = toolset_getarr($this->_data, 'user_default_value', null);
         // Again, handle "0".
         $is_default_value_defined = !empty($default_value) || is_numeric($default_value);
         if ($is_default_value_defined) {
             return stripcslashes($default_value);
         }
     }
     return $actual_value;
 }
Exemplo n.º 5
0
/**
 * Modify field validation rules.
 *
 * Hooked into toolset_filter_field_definition_array. Not to be used elsewhere.
 *
 * Add mandatory validation rules that have not been stored in the database but are needed by Types and toolset-forms
 * to work properly. Namely it's the URL validation for file fields. On the contrary CRED needs these validation rules
 * removed.
 *
 * @param array $field_definition A field definition array.
 * @return array
 * @since 2.2.4
 */
function wpcf_update_mandatory_validation_rules($field_definition, $ignored)
{
    // Add URL validation to file fields (containing URLs).
    //
    // This doesn't include embed files because they are more variable and the URL validation can be
    // configured on the Edit Field Group page.
    $file_fields = array('file', 'image', 'audio', 'video');
    $field_type = toolset_getarr($field_definition, 'type');
    $is_file_field = in_array($field_type, $file_fields);
    $validation_rules = wpcf_ensarr(wpcf_getnest($field_definition, array('data', 'validate')));
    $has_url2_validation = array_key_exists('url2', $validation_rules);
    if ($is_file_field) {
        unset($validation_rules['url']);
        if (!$has_url2_validation) {
            $default_validation_error_message = __('Please enter a valid URL address pointing to the file.', 'wpcf');
            $validation_error_messages = array('file' => $default_validation_error_message, 'audio' => __('Please enter a valid URL address pointing to the audio file.', 'wpcf'), 'image' => __('Please enter a valid URL address pointing to the image file.', 'wpcf'), 'video' => __('Please enter a valid URL address pointing to the video file.', 'wpcf'));
            // The url2 validation doesn't require the TLD part of the URL.
            $validation_rules['url2'] = array('active' => '1', 'message' => toolset_getarr($validation_error_messages, $field_type, $default_validation_error_message), 'suppress_for_cred' => true);
        }
        $field_definition['data']['validate'] = $validation_rules;
    }
    // On the contrary, CRED file fileds MUST NOT use this validation otherwise it won't be possible to
    // submit not changed fields on the edit form. Thus we're making sure that no such rule goes through.
    //
    // These field types come via WPToolset_Types::filterValidation().
    $cred_file_fields = array('credfile', 'credimage', 'credaudio', 'credvideo');
    $is_cred_field = in_array($field_type, $cred_file_fields);
    if ($is_cred_field) {
        unset($validation_rules['url']);
        unset($validation_rules['url2']);
        $field_definition['data']['validate'] = $validation_rules;
    }
    return $field_definition;
}