/** * Prints a filter dropdown for a meta field with flexible input. * * @since 0.6.1 * @param string $column_slug the slug of the meta field column * @param WPPTD\Components\Field $field the field component * @param array $active_filters currently active filters and their values */ protected function render_meta_column_input_filter($column_slug, $field, $active_filters) { $options = Utility::get_all_meta_values($field->slug, $this->component->slug); echo '<select name="' . $column_slug . '" id="' . $column_slug . '" class="postform">'; echo '<option value="">' . esc_html($field->title) . ': ' . __('All', 'post-types-definitely') . '</option>'; foreach ($options as $option) { echo '<option value="' . esc_attr($option) . '"' . (isset($active_filters[$column_slug]) && $active_filters[$column_slug] == $option ? ' selected="selected"' : '') . '>'; echo $field->_field->parse($option, true); echo '</option>'; } echo '</select>'; }
/** * 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; }
/** * 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; }
/** * Returns related users for a specific term. * * Related users of a term are any users which are specified in the registered meta fields of that term (for example in dropdowns). * To register a field like that it must use the special key 'users' in the field's options array. * * @since 0.6.0 * @param $integer $id the term ID to get related users for * @param string $meta_key an optional meta key to only get related users specified as part of that meta key * @param string $role an optional user role to only get related users of that role * @param boolean $single whether to only return a single user (default is false) * @return WP_User|array|null either a WP_User or null (if $single is true) or an array of WP_User objects or empty array otherwise */ function wpptd_get_term_related_users($id, $meta_key = '', $role = '', $single = false) { return \WPPTD\Utility::get_related_objects('term', $id, 'users', $meta_key, $role, $single); }
/** * Renders the meta value of this field for usage in a terms list table column. * * @since 0.6.0 * @param integer $term_id the term ID to display the meta value for */ public function render_table_column($term_id) { $formatted = Utility::get_default_formatted($this->type); $output = wpptd_get_term_meta_value($term_id, $this->slug, null, $formatted); /** * This filter can be used by the developer to modify the way a specific meta value is printed in the terms list table. * * @since 0.6.0 * @param mixed the formatted meta value * @param integer the term ID */ echo apply_filters('wpptd_' . wpptd_get_taxonomy($term_id) . '_term_table_meta_' . $this->slug . '_output', $output, $term_id); }
/** * Validates the arguments array. * * @since 0.5.0 * @param WPPTD\Components\Metabox $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 (isset($this->args['options']) && !is_array($this->args['options'])) { $this->args['options'] = array(); } $this->args['id'] = $this->slug; $this->args['name'] = $this->slug; $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.', 'post-types-definitely'), $this->args['type'], $this->slug), '', ComponentManager::get_scope()); } Utility::maybe_register_related_objects_field($this->_field, $this->args, $this, $parent); if (null === $this->args['default']) { $this->args['default'] = $this->_field->validate(); } $this->args = Utility::validate_position_args($this->args); } return $status; }
/** * 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) { $this->args = Utility::validate_position_args($this->args); } return $status; }