public function register_widgets()
 {
     $widgets = ComponentManager::get('*', 'WPWD\\Components\\Widget');
     foreach ($widgets as $widget) {
         $widget->register();
     }
 }
 function wpcd_get_customizer_setting($panel_slug, $field_slug, $formatted = false)
 {
     if (doing_action('wpcd') || !did_action('wpcd')) {
         if ('general' === $panel_slug) {
             $setting = get_theme_mod($field_slug, null);
             if (!$setting) {
                 $setting = get_option($field_slug, null);
             }
             return $setting;
         }
         $settings = get_theme_mod($panel_slug, array());
         if (!isset($settings[$field_slug])) {
             $settings = get_option($panel_slug, array());
         }
         return isset($settings[$field_slug]) ? $settings[$field_slug] : null;
     }
     $setting = null;
     $field = \WPDLib\Components\Manager::get($panel_slug . '.*.' . $field_slug, 'WPCD\\Components\\Panel', true);
     if ($field) {
         if ('general' === $panel_slug) {
             $setting = \WPCD\Utility::parse_setting('option' === $field->mode ? get_option($field->slug, null) : get_theme_mod($field->slug, null), $field, $formatted);
         } else {
             if ('option' === $field->mode) {
                 $_options = get_option($panel_slug, array());
                 $setting = \WPCD\Utility::parse_setting(isset($_options[$field->slug]) ? $_options[$field->slug] : null, $field, $formatted);
             } else {
                 $_thememods = get_theme_mod($panel_slug, array());
                 $setting = \WPCD\Utility::parse_setting(isset($_thememods[$field->slug]) ? $_thememods[$field->slug] : null, $field, $formatted);
             }
         }
     }
     return $setting;
 }
 /**
  * Returns a single specified option of a tab.
  *
  * This function uses the WordPress core function `get_option()` to get the options array for the tab.
  * If the required field option is not available, this function will automatically return its default value.
  *
  * @since 0.5.0
  * @param string $tab_slug the tab slug to get the option for
  * @param string $field_slug the field slug to get the option for
  * @param boolean $formatted whether to return an automatically formatted value, ready for output (default is false)
  * @return mixed the option
  */
 function wpod_get_option($tab_slug, $field_slug, $formatted = false)
 {
     $_options = get_option($tab_slug, array());
     if (doing_action('wpod') || !did_action('wpod')) {
         if (isset($_options[$field_slug])) {
             return $_options[$field_slug];
         }
         return null;
     }
     $option = null;
     $field = \WPDLib\Components\Manager::get('*.*.' . $tab_slug . '.*.' . $field_slug, 'WPDLib\\Components\\Menu.WPOD\\Components\\Screen', true);
     if ($field) {
         $option = \WPOD\Utility::parse_option(isset($_options[$field->slug]) ? $_options[$field->slug] : null, $field, $formatted);
     }
     return $option;
 }
Esempio n. 4
0
 /**
  * Hooks in all functions related to a taxonomy list table.
  *
  * @since 0.6.0
  */
 protected function add_terms_table_hooks()
 {
     $taxonomies = ComponentManager::get('*.*.*', 'WPDLib\\Components\\Menu.WPPTD\\Components\\PostType.WPPTD\\Components\\Taxonomy');
     foreach ($taxonomies as $taxonomy) {
         $taxonomy_table_handler = $taxonomy->get_table_handler();
         add_filter('manage_edit-' . $taxonomy->slug . '_columns', array($taxonomy_table_handler, 'filter_table_columns'));
         if (0 <= version_compare(get_bloginfo('version'), '4.5')) {
             add_filter('manage_edit-' . $taxonomy->slug . '_sortable_columns', array($taxonomy_table_handler, 'filter_table_sortable_columns'));
         }
         add_filter('manage_' . $taxonomy->slug . '_custom_column', array($taxonomy_table_handler, 'filter_table_column_output'), 10, 3);
         add_filter($taxonomy->slug . '_row_actions', array($this, 'get_term_row_actions'), 10, 2);
     }
     add_action('load-edit-tags.php', array($this, 'handle_term_table_sorting'));
     add_action('load-edit-tags.php', array($this, 'handle_term_row_actions'));
     add_action('load-edit-tags.php', array($this, 'handle_term_bulk_actions'));
 }
 /**
  * Returns a specific field child component of the post type component.
  *
  * @since 0.6.1
  * @param string $field_slug the slug of the field component to get
  * @return WPPTD\Components\Field the field component with the slug $field_slug
  */
 protected function get_child_field($field_slug)
 {
     return ComponentManager::get('*.' . $this->component->slug . '.*.' . $field_slug, 'WPDLib\\Components\\Menu.WPPTD\\Components\\PostType.WPPTD\\Components\\Metabox', true);
 }
Esempio n. 6
0
 /**
  * Registers settings.
  *
  * Registering settings with details was introduced in WordPress 4.7. Therefore this
  * method is not used in versions below that.
  *
  * @since 0.6.7
  * @access public
  *
  * @see WPOD\Components\Tab
  */
 public function register_settings()
 {
     $tabs = ComponentManager::get('*.*.*', 'WPDLib\\Components\\Menu.WPOD\\Components\\Screen');
     foreach ($tabs as $tab) {
         $tab->register();
     }
 }
 public function get_settings()
 {
     $fields = ComponentManager::get('*.*.*', 'WPCD\\Components\\Panel');
     if (count($fields) < 1) {
         return new \stdClass();
     }
     $settings = array();
     foreach ($fields as $field) {
         if ('postMessage' == $field->transport) {
             $settings[$field->_id] = $field->preview_args;
         }
     }
     return $settings;
 }
 /**
  * Returns a single specified meta value for a term.
  *
  * This function is basically a wrapper for the WordPress core function `get_term_meta()`
  * when calling it with specification of a meta key. If the required field meta value is not available,
  * the function will automatically return its default value.
  *
  * Furthermore the $single parameter can be used to force an array or no array to be returned for the
  * meta field. You should generally leave it set to null.
  *
  * @since 0.6.0
  * @param integer $id the term ID to get the meta value for
  * @param string $meta_key the meta key (field slug) to get the meta value for
  * @param null|boolean $single whether to force an array or no array being returned (default is not to force anything)
  * @param boolean $formatted whether to return an automatically formatted value, ready for output (default is false)
  * @return mixed the meta value
  */
 function wpptd_get_term_meta_value($id, $meta_key, $single = null, $formatted = false)
 {
     if (!wpptd_supports_termmeta()) {
         if ($single) {
             return null;
         }
         return array();
     }
     $_meta_value = get_term_meta($id, $meta_key, false);
     if (doing_action('wpptd') || !did_action('wpptd')) {
         if ($single) {
             if (count($_meta_value) > 0) {
                 return $_meta_value[0];
             }
             return null;
         } else {
             return $_meta_value;
         }
     }
     $meta_value = null;
     $field = \WPDLib\Components\Manager::get('*.*.' . wpptd_get_taxonomy($id) . '.*.' . $meta_key, 'WPDLib\\Components\\Menu.WPPTD\\Components\\PostType.WPPTD\\Components\\Taxonomy.WPPTD\\Components\\TermMetabox', true);
     if ($field) {
         $meta_value = \WPPTD\Utility::parse_meta_value($_meta_value, $field, $single, $formatted);
     }
     return $meta_value;
 }
Esempio n. 9
0
 /**
  * Gets the currently active screen and tab.
  *
  * The function checks the currently loaded admin screen.
  * If it is not created by the plugin, the function will return false.
  * Otherwise the output depends on the $type parameter:
  * The function may return the screen object, the tab object or an array of both objects.
  *
  * The second parameter may be used to omit the retrieving process by specifying a screen object.
  * In that case, only the current tab as part of this screen will be looked for.
  *
  * @since 0.5.0
  * @param string $type the type to get the current component for; must be either 'screen', 'tab' or an empty string to get an array of both
  * @param WPOD\Components\Screen|null $screen a screen object to override the retrieving process or null
  * @return WPOD\Components\Screen|WPOD\Components\Tab|array|false either the screen or tab object, an array of both objects or false if no plugin component is currently active
  */
 public function get_current($type = '', $screen = null)
 {
     if (isset($_GET['page'])) {
         if (null === $screen) {
             $screen = ComponentManager::get('*.' . $_GET['page'], 'WPDLib\\Components\\Menu.WPOD\\Components\\Screen', true);
         }
         if (null !== $screen) {
             if ('screen' == $type) {
                 return $screen;
             }
             $tabs = $screen->get_children();
             $tab = null;
             if (isset($_GET['tab'])) {
                 $tab = $tabs[$_GET['tab']];
                 foreach ($tabs as $_tab) {
                     if ($_GET['tab'] == $_tab->slug) {
                         $tab = $_tab;
                         break;
                     }
                 }
             } elseif (count($tabs) > 0) {
                 $tab = array_shift($tabs);
             }
             if (null !== $tab) {
                 if ('tab' == $type) {
                     return $tab;
                 }
                 return compact('screen', 'tab');
             }
         }
     }
     return false;
 }
Esempio n. 10
0
 /**
  * This function is a low-level function to get related objects for another specific object.
  *
  * The base object can either be a post or a term (specified by an ID) while the related objects
  * can either be posts, terms or users.
  *
  * The function looks through the registered meta fields of the base object that possibly
  * contain related objects. It is also possible to only return related objects that are stored
  * in a specific meta field or that have a specific type (that is post type, taxonomy or user role).
  *
  * @see wpptd_get_post_related_posts()
  * @see wpptd_get_post_related_terms()
  * @see wpptd_get_post_related_users()
  * @see wpptd_get_term_related_posts()
  * @see wpptd_get_term_related_terms()
  * @see wpptd_get_term_related_users()
  * @since 0.6.0
  * @param string $mode mode of the ID specified (for the base object), either 'post' or 'term'
  * @param integer $id a post ID or a term ID (depending the $mode parameter)
  * @param string $objects_mode mode of the related objects to find, either 'posts', 'terms' or 'users'
  * @param string $meta_key an optional meta key to only return objects that are stored in a meta field of that name (default is empty)
  * @param string $object_type an optional type to only return objects of that type, either a specific post type, taxonomy or user role depending on the $objects_mode parameter
  * @param boolean $single whether to only return a single object (default is false)
  * @return WP_Post|WP_Term|WP_User|array|null either an object or null (if $single is true) or an array of objects or empty array otherwise
  */
 public static function get_related_objects($mode, $id, $objects_mode, $meta_key = '', $object_type = '', $single = false)
 {
     // specify variables depending on the base mode
     switch ($mode) {
         case 'post':
             $get_func = 'get_post';
             $type_field = 'post_type';
             $component_path = '*.[TYPE]';
             $class_path = 'WPDLib\\Components\\Menu.WPPTD\\Components\\PostType';
             $meta_func = 'wpptd_get_post_meta_value';
             break;
         case 'term':
             if (!wpptd_supports_termmeta()) {
                 if ($single) {
                     return null;
                 }
                 return array();
             }
             $get_func = 'get_term';
             $type_field = 'taxonomy';
             $component_path = '*.*.[TYPE]';
             $class_path = 'WPDLib\\Components\\Menu.WPPTD\\Components\\PostType.WPPTD\\Components\\Taxonomy';
             $meta_func = 'wpptd_get_term_meta_value';
             break;
         default:
             if ($single) {
                 return null;
             }
             return array();
     }
     // specify variables depending on the objects mode
     switch ($objects_mode) {
         case 'posts':
             $objects_related_field = 'related_posts_fields';
             $objects_get_func = 'get_post';
             $objects_type_field = 'post_type';
             break;
         case 'terms':
             $objects_related_field = 'related_terms_fields';
             $objects_get_func = 'get_term';
             $objects_type_field = 'taxonomy';
             break;
         case 'users':
             $objects_related_field = 'related_users_fields';
             $objects_get_func = 'get_user_by';
             $objects_get_func_first_param = 'id';
             $objects_type_field = 'roles';
             break;
         default:
             if ($single) {
                 return null;
             }
             return array();
     }
     // get the base object
     $obj = call_user_func($get_func, $id);
     if (!$obj) {
         if ($single) {
             return null;
         }
         return array();
     }
     // get the component for the base object
     $component = ComponentManager::get(str_replace('[TYPE]', $obj->{$type_field}, $component_path), $class_path, true);
     if (!$component) {
         if ($single) {
             return null;
         }
         return array();
     }
     // get the necessary meta fields depending on the $meta_key and $object_type parameter
     $all_fields = $component->{$objects_related_field};
     $fields = array();
     if (!empty($meta_key) && !empty($object_type)) {
         if (isset($all_fields[$meta_key]) && (0 === count($all_fields[$meta_key]) || in_array($object_type, $all_fields[$meta_key], true))) {
             $fields[] = $meta_key;
         }
     } elseif (!empty($meta_key)) {
         if (isset($all_fields[$meta_key])) {
             $fields[] = $meta_key;
         }
     } elseif (!empty($object_type)) {
         foreach ($all_fields as $field_name => $types) {
             if (0 === count($types) || in_array($object_type, $types, true)) {
                 $fields[] = $field_name;
             }
         }
     } else {
         $fields = array_keys($all_fields);
     }
     if (0 === count($fields)) {
         if ($single) {
             return null;
         }
         return array();
     }
     // get the IDs of the related objects
     $object_ids = array();
     foreach ($fields as $field) {
         $val = call_user_func($meta_func, $id, $field);
         if (!$val) {
             continue;
         } elseif (is_array($val)) {
             $object_ids = array_merge($object_ids, $val);
         } else {
             $object_ids[] = $val;
         }
     }
     $object_ids = array_filter(array_map('absint', $object_ids));
     if (0 === count($object_ids)) {
         if ($single) {
             return null;
         }
         return array();
     }
     // get the related objects, also considering the $object_type variable if applicable
     $objects = array();
     foreach ($object_ids as $object_id) {
         if (isset($objects_get_func_first_param)) {
             $object = call_user_func($objects_get_func, $objects_get_func_first_param, $object_id);
         } else {
             $object = call_user_func($objects_get_func, $object_id);
         }
         if (!$object) {
             continue;
         }
         if (!empty($object_type)) {
             $type = $object->{$objects_type_field};
             if (is_array($type) && !in_array($object_type, $type, true)) {
                 continue;
             } elseif (!is_array($type) && $object_type !== $type) {
                 continue;
             }
         }
         $objects[] = $object;
     }
     if (0 === count($objects)) {
         if ($single) {
             return null;
         }
         return array();
     }
     if ($single) {
         return $objects[0];
     }
     return $objects;
 }
Esempio n. 11
0
 /**
  * Registers meta for all post types and taxonomies.
  *
  * Registering metadata with details was introduced in WordPress 4.6. Therefore this
  * method is not used in versions below that.
  *
  * @see WPPTD\Components\PostType
  * @see WPPTD\Components\Taxonomy
  * @since 0.6.5
  */
 public function register_meta()
 {
     $post_types = ComponentManager::get('*.*', 'WPDLib\\Components\\Menu.WPPTD\\Components\\PostType');
     foreach ($post_types as $post_type) {
         $post_type->register_meta();
     }
     $taxonomies = ComponentManager::get('*.*.*', 'WPDLib\\Components\\Menu.WPPTD\\Components\\PostType.WPPTD\\Components\\Taxonomy');
     foreach ($taxonomies as $taxonomy) {
         $taxonomy->register_meta();
     }
 }
 public function print_customizer_styles($wrap_style_tags = true)
 {
     $panels = ComponentManager::get('*', 'WPCD\\Components\\Panel');
     foreach ($panels as $panel) {
         foreach ($panel->get_children() as $section) {
             foreach ($section->get_children() as $field) {
                 $preview_args = $field->preview_args;
                 if ('update_style' === $preview_args['update_callback']) {
                     $value = wpcd_get_customizer_setting($panel->slug, $field->slug);
                     $value = $this->preprocess_customizer_setting($value, $preview_args['preprocess_callback'], $preview_args['preprocess_args']);
                     if ($wrap_style_tags) {
                         echo '<style type="text/css" id="wpcd-customizer-style-' . $this->sanitize_id($field->_id) . '">';
                     }
                     $this->print_field_styles($value, $preview_args['update_args']);
                     if ($wrap_style_tags) {
                         echo '</style>' . "\n";
                     }
                 }
             }
         }
     }
 }