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; }
public function register_widgets() { $widgets = ComponentManager::get('*', 'WPWD\\Components\\Widget'); foreach ($widgets as $widget) { $widget->register(); } }
/** * 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; }
/** * 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(); } }
/** * Checks if the slug of the component is valid. * * @since 0.5.0 * @param WPDLib\Components\Base $parent the parent component of the component * @return bool whether the component slug is valid */ public function is_valid_slug($parent = null) { if ($this->valid_slug === null) { $globalnames = $this->supports_globalslug(); if ($globalnames !== true) { if ($globalnames !== false) { $found = false; $parent = $this->get_parent(); if ($parent !== null) { $found = true; while (get_class($parent) != $globalnames) { $parent = $parent->get_parent(); if ($parent === null) { $found = false; break; } } } if ($found) { $this->valid_slug = !ComponentManager::exists($this->slug, get_class($this), $parent->slug); } else { $this->valid_slug = !ComponentManager::exists($this->slug, get_class($this)); } } else { $this->valid_slug = !ComponentManager::exists($this->slug, get_class($this)); } } else { ComponentManager::exists($this->slug, get_class($this)); // just use the function to add the component $this->valid_slug = true; } } return $this->valid_slug; }
/** * Validates the arguments array. * * @since 0.5.0 * @param WPDLib\Components\Menu $parent the parent component * @return bool|WPDLib\Util\Error an error object if an error occurred during validation, true if it was validated, false if it did not need to be validated */ public function validate($parent = null) { $status = parent::validate($parent); if ($status === true) { if (in_array($this->slug, array('revision', 'nav_menu_item', 'action', 'author', 'order', 'plugin', 'theme'))) { return new UtilError('no_valid_post_type', sprintf(__('The post type slug %s is forbidden since it would interfere with WordPress Core functionality.', 'post-types-definitely'), $this->slug), '', ComponentManager::get_scope()); } // show notice if slug contains dashes if (strpos($this->slug, '-') !== false) { App::doing_it_wrong(__METHOD__, sprintf(__('The post type slug %s contains dashes which is discouraged. It will still work for the most part, but we recommend to adjust the slug if possible.', 'post-types-definitely'), $this->slug), '0.5.0'); } // generate titles if not provided $this->args = Utility::validate_titles($this->args, $this->slug, 'post_type'); // generate post type labels $this->args = Utility::validate_labels($this->args, 'labels', 'post_type'); // generate post type updated messages $this->args = Utility::validate_labels($this->args, 'messages', 'post_type'); // generate post type bulk action messages $this->args = Utility::validate_labels($this->args, 'bulk_messages', 'post_type'); // set some defaults if (null === $this->args['rewrite']) { if ($this->args['public']) { $this->args['rewrite'] = array('slug' => str_replace('_', '-', $this->slug), 'with_front' => false, 'ep_mask' => EP_PERMALINK); } else { $this->args['rewrite'] = false; } } // handle REST API default if (null === $this->args['show_in_rest']) { if (null !== $this->args['publicly_queryable']) { $this->args['show_in_rest'] = $this->args['publicly_queryable']; } elseif (null !== $this->args['public']) { $this->args['show_in_rest'] = $this->args['public']; } else { $this->args['show_in_rest'] = false; } } $this->args = Utility::validate_ui_args($this->args); $menu = $this->get_parent(); if ($this->args['show_in_menu'] && empty($menu->slug)) { $this->args['show_in_menu'] = true; } elseif ($this->args['show_in_menu']) { $this->args['show_in_menu'] = false; if (null === $this->args['show_in_admin_bar']) { $this->args['show_in_admin_bar'] = true; } $this->show_in_menu_manually = true; if (isset($this->args['menu_position'])) { App::doing_it_wrong(__METHOD__, sprintf(__('A menu position is unnecessarily provided for the post type %s - the menu position is already specified by its parent menu.', 'post-types-definitely'), $this->slug), '0.5.0'); unset($this->args['menu_position']); } if (isset($this->args['menu_icon'])) { App::doing_it_wrong(__METHOD__, sprintf(__('A menu icon is unnecessarily provided for the post type %s - the menu icon is already specified by its parent menu.', 'post-types-definitely'), $this->slug), '0.5.0'); unset($this->args['menu_icon']); } } $this->args = Utility::validate_position_args($this->args); // handle post table $this->args = PostTypeTableHandler::validate_args($this->args); // handle help $this->args = Utility::validate_help_args($this->args, 'help'); // handle list help $this->args = Utility::validate_help_args($this->args, 'list_help'); } return $status; }
/** * Enqueues required assets for the field type. * * The function also generates script vars to be applied in `wp_localize_script()`. * * @since 0.5.0 * @return array array which can (possibly) contain a 'dependencies' array and a 'script_vars' array */ public function enqueue_assets() { if (self::is_enqueued(__CLASS__)) { return array(); } $assets_dir = ComponentManager::get_base_dir() . '/assets'; $assets_url = ComponentManager::get_base_url() . '/assets'; $version = ComponentManager::get_dependency_info('select2', 'version'); $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_style('select2', $assets_url . '/vendor/select2/dist/css/select2' . $min . '.css', array(), $version); wp_enqueue_script('select2', $assets_url . '/vendor/select2/dist/js/select2' . $min . '.js', array('jquery'), $version, true); $dependencies = array('select2'); $locale = str_replace('_', '-', get_locale()); $language = substr($locale, 0, 2); if (file_exists($assets_dir . '/vendor/select2/dist/js/i18n/' . $locale . '.js')) { wp_enqueue_script('select2-locale', $assets_url . '/vendor/select2/dist/js/i18n/' . $locale . '.js', array('select2'), $version, true); $dependencies[] = 'select2-locale'; } elseif (file_exists($assets_dir . '/vendor/select2/dist/js/i18n/' . $language . '.js')) { wp_enqueue_script('select2-locale', $assets_url . '/vendor/select2/dist/js/i18n/' . $language . '.js', array('select2'), $version, true); $dependencies[] = 'select2-locale'; } return array('dependencies' => $dependencies); }
/** * Validates the arguments array. * * @since 0.5.0 * @param WPWD\Components\Section $parent the parent component * @return bool|WPDLib\Util\Error an error object if an error occurred during validation, true if it was validated, false if it did not need to be validated */ public function validate($parent = null) { $status = parent::validate($parent); if ($status === true) { if (is_array($this->args['class'])) { $this->args['class'] = implode(' ', $this->args['class']); } if (!empty($this->args['class'])) { $this->args['class'] .= ' '; } $this->args['class'] .= 'widefat'; if (isset($this->args['options']) && !is_array($this->args['options'])) { $this->args['options'] = array(); } $this->_field = FieldManager::get_instance($this->args); if ($this->_field === null) { return new UtilError('no_valid_field_type', sprintf(__('The field type %1$s assigned to the field component %2$s is not a valid field type.', 'widgets-definitely'), $this->args['type'], $this->slug), '', ComponentManager::get_scope()); } if (null === $this->args['default']) { $this->args['default'] = $this->_field->validate(); } $this->args = Utility::validate_position_args($this->args); } return $status; }
/** * Initializes the plugin framework. * * This function adds all components to the plugin. It is executed on the 'after_setup_theme' hook with priority 1. * The action 'wpod' should be used to add all the components. * * @internal * @see WPOD\App::add_components() * @see WPOD\App::add() * @since 0.5.0 */ public function init() { if (!did_action('wpod')) { /** * This filter can be used to alter the component hierarchy of the plugin. * It must only be used to add more components to the hierarchy, never to change or remove something existing. * * @since 0.5.0 * @param array the nested array of component class names */ ComponentManager::register_hierarchy(apply_filters('wpod_class_hierarchy', array('WPDLib\\Components\\Menu' => array('WPOD\\Components\\Screen' => array('WPOD\\Components\\Tab' => array('WPOD\\Components\\Section' => array('WPOD\\Components\\Field' => array()))))))); /** * The main API action of the plugin. * * Every developer must hook into this action to register components. * * @since 0.5.0 * @param WPOD\App instance of the main plugin class */ do_action('wpod', $this); } else { self::doing_it_wrong(__METHOD__, __('This function should never be called manually.', 'options-definitely'), '0.5.0'); } }
/** * 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); }
/** * 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 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; }
/** * Validates the arguments array. * * @since 0.5.0 */ public function validate($parent = null) { $status = parent::validate($parent); if ($status === true) { if (null === $this->args['capability']) { $this->args['capability'] = $parent->capability; } if (isset($this->args['priority'])) { if (null === $this->args['position']) { $this->args['position'] = $this->args['priority']; } unset($this->args['priority']); } $this->args = Utility::validate_position_args($this->args); if (null === $this->args['mode']) { $this->args['mode'] = $parent->get_parent()->mode; } if (is_array($this->args['class'])) { $this->args['class'] = implode(' ', $this->args['class']); } if (isset($this->args['options']) && !is_array($this->args['options'])) { $this->args['options'] = array(); } if (in_array($this->args['type'], array('multiselect', 'multibox'), true)) { return new UtilError('multichoice_not_supported', sprintf(__('The multichoice field type assigned to the field component %s is not supported in the Customizer.', 'customizer-definitely'), $this->slug), '', ComponentManager::get_scope()); } if ('repeatable' == $this->args['type']) { return new UtilError('repeatable_not_supported', sprintf(__('The repeatable field type assigned to the field component %s is not supported in the Customizer.', 'customizer-definitely'), $this->slug), '', ComponentManager::get_scope()); } $this->_field = FieldManager::get_instance($this->args); if (null === $this->_field) { return new UtilError('no_valid_field_type', sprintf(__('The field type %1$s assigned to the field component %2$s is not a valid field type.', 'customizer-definitely'), $this->args['type'], $this->slug), '', ComponentManager::get_scope()); } if (null === $this->args['default']) { $this->args['default'] = $this->_field->validate(); } $this->args['preview_args'] = Customizer::instance()->validate_preview_args($this->args['preview_args'], $this->args['type'], $this->_field); if (null === $this->args['transport']) { if ($this->args['preview_args']['update_callback']) { $this->args['transport'] = 'postMessage'; } else { $this->args['transport'] = 'refresh'; } } } return $status; }
/** * 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; }
/** * 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; }
/** * 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(); } }
/** * Initializes the plugin framework. * * This function adds all components to the plugin. It is executed on the 'after_setup_theme' hook with priority 5. * The action 'wpptd' should be used to add all the components. * * @internal * @see WPPTD\App::add_components() * @see WPPTD\App::add() * @since 0.5.0 */ public function init() { if (!did_action('wpptd')) { $hierarchy = array('WPDLib\\Components\\Menu' => array('WPPTD\\Components\\PostType' => array('WPPTD\\Components\\Metabox' => array('WPPTD\\Components\\Field' => array()), 'WPPTD\\Components\\Taxonomy' => array()))); if (wpptd_supports_termmeta()) { $hierarchy['WPDLib\\Components\\Menu']['WPPTD\\Components\\PostType']['WPPTD\\Components\\Taxonomy'] = array('WPPTD\\Components\\TermMetabox' => array('WPPTD\\Components\\TermField' => array())); } /** * This filter can be used to alter the component hierarchy of the plugin. * It must only be used to add more components to the hierarchy, never to change or remove something existing. * * @since 0.5.0 * @param array the nested array of component class names */ ComponentManager::register_hierarchy(apply_filters('wpptd_class_hierarchy', $hierarchy)); /** * The main API action of the plugin. * * Every developer must hook into this action to register components. * * @since 0.5.0 * @param WPPTD\App instance of the main plugin class */ do_action('wpptd', $this); $this->taxonomies_temp = array(); } else { self::doing_it_wrong(__METHOD__, __('This function should never be called manually.', 'post-types-definitely'), '0.5.0'); } }
/** * Enqueues required assets for the field type. * * The function also generates script vars to be applied in `wp_localize_script()`. * * @since 0.6.0 * @return array array which can (possibly) contain a 'dependencies' array and a 'script_vars' array */ public function enqueue_assets() { if (self::is_enqueued(__CLASS__)) { return array(); } $assets_url = ComponentManager::get_base_url() . '/assets'; $version = ComponentManager::get_dependency_info('wp-map-picker', 'version'); $gmaps_url = 'https://maps.google.com/maps/api/js'; $gmaps_args = array('language' => str_replace('_', '-', get_locale())); if ($api_key = self::get_api_key()) { $gmaps_args['key'] = $api_key; } $gmaps_url = add_query_arg($gmaps_args, $gmaps_url); wp_enqueue_script('google-maps', $gmaps_url, array(), false, true); $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_style('wp-map-picker', $assets_url . '/vendor/wp-map-picker/wp-map-picker' . $min . '.css', array(), $version); wp_enqueue_script('wp-map-picker', $assets_url . '/vendor/wp-map-picker/wp-map-picker' . $min . '.js', array('jquery', 'jquery-ui-widget', 'jquery-ui-autocomplete', 'google-maps'), $version, true); return array('dependencies' => array('wp-map-picker')); }
/** * Enqueues required assets for the field type. * * The function also generates script vars to be applied in `wp_localize_script()`. * * @since 0.5.0 * @return array array which can (possibly) contain a 'dependencies' array and a 'script_vars' array */ public function enqueue_assets() { global $post; if (self::is_enqueued(__CLASS__)) { return array(); } $assets_url = ComponentManager::get_base_url() . '/assets'; $version = ComponentManager::get_dependency_info('wp-media-picker', 'version'); if ($post) { wp_enqueue_media(array('post' => $post->ID)); } else { wp_enqueue_media(); } $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_style('wp-media-picker', $assets_url . '/vendor/wp-media-picker/wp-media-picker' . $min . '.css', array(), $version); wp_enqueue_script('wp-media-picker', $assets_url . '/vendor/wp-media-picker/wp-media-picker' . $min . '.js', array('jquery', 'jquery-ui-widget', 'media-editor'), $version, true); return array('dependencies' => array('media-editor', 'wp-media-picker'), 'script_vars' => array('media_i18n_add' => __('Choose a File', 'wpdlib'), 'media_i18n_replace' => __('Choose another File', 'wpdlib'), 'media_i18n_remove' => __('Remove', 'wpdlib'), 'media_i18n_modal' => __('Choose a File', 'wpdlib'), 'media_i18n_button' => __('Insert File', 'wpdlib'))); }
/** * Initializes the plugin framework. * * This function adds all components to the plugin. It is executed on the 'after_setup_theme' hook with priority 3. * The action 'wpcd' should be used to add all the components. * * @internal * @see WPCD\App::add_components() * @see WPCD\App::add() * @since 0.5.0 */ public function init() { if (!did_action('wpcd')) { ComponentManager::register_hierarchy(apply_filters('wpcd_class_hierarchy', array('WPCD\\Components\\Panel' => array('WPCD\\Components\\Section' => array('WPCD\\Components\\Field' => array()))))); do_action('wpcd', $this); } else { self::doing_it_wrong(__METHOD__, __('This function should never be called manually.', 'customizer-definitely'), '0.5.0'); } }
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; }
/** * Enqueues assets for one or more fields. * * This function should be used from all places in the WordPress admin that contain field types from WPDLib. * All fields active on the screen should be passed to the function. * * @since 0.5.0 * @param array $fields the field type objects to enqueue assets for */ public static function enqueue_assets($fields = array()) { $assets_url = ComponentManager::get_base_url() . '/assets'; $version = ComponentManager::get_info('version'); list($dependencies, $script_vars) = self::get_dependencies_and_script_vars($fields); if (!in_array('jquery', $dependencies)) { $dependencies[] = 'jquery'; } $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_style('wpdlib-fields', $assets_url . '/dist/css/fields' . $min . '.css', array(), $version); wp_enqueue_script('wpdlib-fields', $assets_url . '/dist/js/fields' . $min . '.js', $dependencies, $version, true); wp_localize_script('wpdlib-fields', '_wpdlib_data', $script_vars); }
/** * Validates the arguments array. * * @since 0.5.0 * @param WPPTD\Components\PostType $parent the parent component * @return bool|WPDLib\Util\Error an error object if an error occurred during validation, true if it was validated, false if it did not need to be validated */ public function validate($parent = null) { $status = parent::validate($parent); if ($status === true) { if (in_array($this->slug, array('post_format', 'link_category', 'nav_menu'))) { return new UtilError('no_valid_taxonomy', sprintf(__('The taxonomy slug %s is forbidden since it would interfere with WordPress Core functionality.', 'post-types-definitely'), $this->slug), '', ComponentManager::get_scope()); } // show notice if slug contains dashes if (strpos($this->slug, '-') !== false) { App::doing_it_wrong(__METHOD__, sprintf(__('The taxonomy slug %s contains dashes which is discouraged. It will still work for the most part, but we recommend to adjust the slug if possible.', 'post-types-definitely'), $this->slug), '0.5.0'); } // generate titles if not provided $this->args = Utility::validate_titles($this->args, $this->slug, 'taxonomy'); // generate taxonomy labels $this->args = Utility::validate_labels($this->args, 'labels', 'taxonomy'); // generate taxonomy updated messages $this->args = Utility::validate_labels($this->args, 'messages', 'taxonomy'); // set some defaults if (null === $this->args['rewrite']) { if ($this->args['public']) { $this->args['rewrite'] = array('slug' => str_replace('_', '-', $this->slug), 'with_front' => true, 'hierarchical' => $this->args['hierarchical'], 'ep_mask' => EP_NONE); } else { $this->args['rewrite'] = false; } } // handle REST API default if (null === $this->args['show_in_rest']) { if (null !== $this->args['public']) { $this->args['show_in_rest'] = $this->args['public']; } else { $this->args['show_in_rest'] = false; } } $this->args = Utility::validate_ui_args($this->args); $this->args = Utility::validate_position_args($this->args); // handle term table $this->args = TaxonomyTableHandler::validate_args($this->args); // handle help $this->args = Utility::validate_help_args($this->args, 'help'); // handle list help $this->args = Utility::validate_help_args($this->args, 'list_help'); } return $status; }
* @return WPDLib\Components\Base the first component with the second component merged into it */ private static function merge_components($a, $b) { $args = $a->args; $parents = $a->parents; $children = $a->children; $_args = $b->args; $_parents = $b->parents; $_children = $b->children; $a->args = array_merge($args, $_args); $a->parents = array_merge($parents, $_parents); $a->children = array_merge_recursive($children, $_children); return $a; } /** * Determines the base path and base URL to WPDLib. * * @since 0.5.0 */ private static function determine_base() { self::$base_dir = str_replace('/inc/WPDLib/Components', '', wp_normalize_path(dirname(__FILE__))); self::$base_url = str_replace(WP_CONTENT_DIR, WP_CONTENT_URL, self::$base_dir); } } // automatically load the WPDLib textdomain Manager::load_textdomain(); // automatically create menu from all menu components add_action('admin_menu', array('WPDLib\\Components\\Manager', 'create_menu'), 40); }
/** * Enqueues required assets for the field type. * * The function also generates script vars to be applied in `wp_localize_script()`. * * @since 0.5.0 * @return array array which can (possibly) contain a 'dependencies' array and a 'script_vars' array */ public function enqueue_assets() { if (self::is_enqueued(__CLASS__)) { return array(); } $assets_url = ComponentManager::get_base_url() . '/assets'; $version = ComponentManager::get_dependency_info('datetimepicker', 'version'); $min = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_style('datetimepicker', $assets_url . '/vendor/datetimepicker/jquery.datetimepicker.css', array(), $version); wp_enqueue_script('datetimepicker', $assets_url . '/vendor/datetimepicker/build/jquery.datetimepicker.full' . $min . '.js', array('jquery'), $version, true); return array('dependencies' => array('datetimepicker'), 'script_vars' => array('language' => substr(get_locale(), 0, 2), 'date_format' => get_option('date_format'), 'time_format' => get_option('time_format'), 'start_of_week' => get_option('start_of_week'))); }
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"; } } } } } }