/** * Create new field group. * * @param string $name Sanitized field group name. Note that the final name may change when new post is inserted. * @param string $title Field group title. * * @return null|Types_Field_Group The new field group or null on error. */ public static function create($name, $title = '') { // we cannot use self::get_instance here, because of low PHP requirements and missing get_called_class function // we have a fallback class for get_called_class but that scans files by debug_backtrace and return 'self' // instead of Types_Field_Group_Term_Factory like the original get_called_class() function does // ends in an error because of parents (abstract) $var = new self(); return Types_Field_Group_Term_Factory::get_instance()->create_field_group($name, $title); }
/** * For a given field domain, return the appropriate field group factory instance. * * @param string $domain Valid field domain * @return Types_Field_Group_Factory * @since 2.1 */ public static function get_factory_by_domain($domain) { switch ($domain) { case Types_Field_Utils::DOMAIN_POSTS: return Types_Field_Group_Post_Factory::get_instance(); case Types_Field_Utils::DOMAIN_USERS: return Types_Field_Group_User_Factory::get_instance(); case Types_Field_Utils::DOMAIN_TERMS: return Types_Field_Group_Term_Factory::get_instance(); default: throw new InvalidArgumentException('Invalid field domain.'); } }
function prepare_items() { $per_page = $this->get_items_per_page(WPCF_Page_Listing_Termmeta::SCREEN_OPTION_PER_PAGE_NAME, WPCF_Page_Listing_Termmeta::SCREEN_OPTION_PER_PAGE_DEFAULT_VALUE); $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); $this->_column_headers = array($columns, $hidden, $sortable); $this->process_bulk_action(); $search_string = isset($_POST['s']) ? mb_strtolower(trim($_POST['s'])) : null; $query_args = array('orderby' => sanitize_text_field(wpcf_getget('orderby', 'post_title')), 'order' => sanitize_text_field(wpcf_getget('order', 'asc')), 'types_search' => $search_string); $groups = Types_Field_Group_Term_Factory::get_instance()->query_groups($query_args); /** * REQUIRED for pagination. Let's figure out what page the user is currently * looking at. We'll need this later, so you should always include it in * your own package classes. */ $current_page = $this->get_pagenum(); /** * REQUIRED for pagination. Let's check how many items are in our data array. * In real-world use, this would be the total number of items in your database, * without filtering. We'll need this later, so you should always include it * in your own package classes. */ $total_items = count($groups); /** * The WP_List_Table class does not handle pagination for us, so we need * to ensure that the data is trimmed to only the current page. We can use * array_slice() to */ $groups = array_slice($groups, ($current_page - 1) * $per_page, $per_page); /** * REQUIRED. Now we can add our *sorted* data to the items property, where * it can be used by the rest of the class. */ $this->items = $groups; /** * REQUIRED. We also have to register our pagination options & calculations. */ $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page))); }
/** * This should be executed when user *updates* the screen options for hiding table columns. * * It signifies a deliberate action, which means that the user is already aware of the screen options and we can * disable the autohiding mechanism for good. * * @param string $taxonomy_slug * @param string[] $hidden_columns Hidden column names. * @param string $screen_id ID of the screen where column autohiding might be disabled. * @since 2.1 */ public function maybe_disable_column_autohiding($taxonomy_slug, $hidden_columns, $screen_id) { $factory = Types_Field_Group_Term_Factory::get_instance(); $groups = $factory->get_groups_by_taxonomy($taxonomy_slug); if (empty($groups) || !is_array($hidden_columns)) { // Nothing to do here return; } foreach ($hidden_columns as $column) { if ($this->is_term_field_column($column)) { // Some columns are hidden anyway, no need to do anything return; } } // All term field columns are being displayed on purpose - after this we'll never do the autohide. update_user_option(get_current_user_id(), self::USER_OPTION_DISABLE_COLUMN_AUTOHIDING . $screen_id, 1); }
/** * Add form inputs related to term field group and field definition import. * * @param SimpleXMLElement $data Import data from XML * @return array Enlimbo form elements (yuck). * @since 2.1 */ function wpcf_admin_import_export_settings_for_terms($data) { $form = array(); if (!empty($data->term_groups)) { $form['title-terms'] = array('#type' => 'markup', '#markup' => '<h2>' . __('Term field groups to be added or updated', 'wpcf') . '</h2>'); $group_factory = Types_Field_Group_Term_Factory::get_instance(); $groups_check = array(); foreach ($data->term_groups->group as $group) { $group = (array) $group; $group_id = $group['ID']; $group_slug = $group['post_title']; $form['term-group-add-' . $group_id] = array('#type' => 'checkbox', '#name' => 'term_groups[' . $group_id . '][add]', '#default_value' => true, '#title' => '<strong>' . esc_html($group_slug) . '</strong>', '#inline' => true, '#after' => '<br /><br />'); $existing_groups = $group_factory->query_groups(array('name' => $group_slug, 'post_type' => $group['post_type'])); $group_already_exists = count($existing_groups) > 0; if ($group_already_exists) { $form['term-group-add-' . $group_id]['#after'] = wpcf_form_simple(array('term-group-add-update-' . $group_id => array('#type' => 'radios', '#name' => 'term_groups[' . $group_id . '][update]', '#inline' => true, '#options' => array(__('Update', 'wpcf') => 'update', __('Create new', 'wpcf') => 'add'), '#default_value' => 'update', '#before' => '<br />', '#after' => '<br />'))); } $groups_check[] = $group_slug; } $groups_existing = get_posts(array('post_type' => Types_Field_Group_Term::POST_TYPE, 'post_status' => null)); if (!empty($groups_existing)) { $groups_to_be_deleted = array(); foreach ($groups_existing as $post) { if (!in_array($post->post_title, $groups_check)) { $groups_to_be_deleted['<strong>' . $post->post_title . '</strong>'] = $post->ID; } } if (!empty($groups_to_be_deleted)) { $form['title-term-groups-deleted'] = array('#type' => 'markup', '#markup' => '<h2>' . __('Term groups to be deleted', 'wpcf') . '</h2>'); $form['term-groups-deleted'] = array('#type' => 'checkboxes', '#name' => 'term-groups-to-be-deleted', '#options' => $groups_to_be_deleted); } } } // Check term fields if (!empty($data->term_fields)) { $form['term-title-fields'] = array('#type' => 'markup', '#markup' => '<h2>' . __('Term fields to be added/updated', 'wpcf') . '</h2>'); $fields_existing = wpcf_admin_fields_get_fields(false, false, false, WPCF_Field_Definition_Factory_Term::FIELD_DEFINITIONS_OPTION); $fields_check = array(); $fields_to_be_deleted = array(); foreach ($data->term_fields->field as $field) { $field = (array) $field; if (empty($field['id']) || empty($field['name'])) { continue; } $form['term-field-add-' . $field['id']] = array('#type' => 'checkbox', '#name' => 'term_fields[' . $field['id'] . '][add]', '#default_value' => true, '#title' => '<strong>' . $field['name'] . '</strong>', '#inline' => true, '#after' => '<br />'); $fields_check[] = $field['id']; } foreach ($fields_existing as $field_id => $field) { if (!in_array($field_id, $fields_check)) { $fields_to_be_deleted['<strong>' . $field['name'] . '</strong>'] = $field['id']; } } if (!empty($fields_to_be_deleted)) { $form['term-title-fields-deleted'] = array('#type' => 'markup', '#markup' => '<h2>' . __('Term ields to be deleted', 'wpcf') . '</h2>'); $form['term-fields-deleted'] = array('#type' => 'checkboxes', '#name' => 'term-fields-to-be-deleted', '#options' => $fields_to_be_deleted); } } return $form; }
/** * @inheritdoc * @return Types_Field_Group_Post_Factory * @since 2.0 */ public function get_group_factory() { return Types_Field_Group_Term_Factory::get_instance(); }