コード例 #1
0
 /**
  * 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|WPCF_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 WPCF_Field_Group_Term_Factory like the original get_called_class() function does
     // ends in an error because of parents (abstract) $var = new self();
     return WPCF_Field_Group_Term_Factory::get_instance()->create_field_group($name, $title);
 }
コード例 #2
0
 /**
  * @return WPCF_Field_Group[]
  */
 public function get_associated_groups()
 {
     $term_field_groups = WPCF_Field_Group_Term_Factory::get_instance()->query_groups();
     $associated_groups = array();
     foreach ($term_field_groups as $field_group) {
         if ($field_group->contains_field_definition($this)) {
             $associated_groups[] = $field_group;
         }
     }
     return $associated_groups;
 }
コード例 #3
0
ファイル: utils.php プロジェクト: axeljohansson1988/oddcv
 /**
  * For a given field domain, return the appropriate field group factory instance.
  *
  * @param string $domain
  * @return WPCF_Field_Group_Factory
  * @since 2.0
  */
 public static function get_group_factory_by_domain($domain)
 {
     switch ($domain) {
         case self::DOMAIN_POSTS:
             return WPCF_Field_Group_Post_Factory::get_instance();
         case self::DOMAIN_USERS:
             return WPCF_Field_Group_User_Factory::get_instance();
         case self::DOMAIN_TERMS:
             return WPCF_Field_Group_Term_Factory::get_instance();
         default:
             throw new InvalidArgumentException('Invalid field domain.');
     }
 }
コード例 #4
0
 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')));
     $groups = WPCF_Field_Group_Term_Factory::get_instance()->query_groups($query_args, $search_string);
     /**
      * 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)));
 }
コード例 #5
0
 /**
  * @inheritdoc
  * @return WPCF_Field_Group_Post_Factory
  * @since 2.0
  */
 public function get_group_factory()
 {
     return WPCF_Field_Group_Term_Factory::get_instance();
 }
コード例 #6
0
ファイル: termmeta_form.php プロジェクト: phuocdungit/fundy
 private function load_field_group($field_group_id)
 {
     return WPCF_Field_Group_Term_Factory::load($field_group_id);
 }
コード例 #7
0
 public function on_term_update($term_id, $tt_id)
 {
     // Get an array of fields that we need to update. We don't care about their groups here.
     $term = get_term_by('term_taxonomy_id', $tt_id);
     if (!$term instanceof WP_Term) {
         return;
     }
     $groups = WPCF_Field_Group_Term_Factory::get_instance()->get_groups_by_taxonomy($term->taxonomy);
     if (empty($groups)) {
         return;
     }
     $field_definitions = WPCF_Field_Utils::get_field_definitions_from_groups($groups);
     $update_errors = $this->update_term_fields($term_id, $field_definitions);
     // Display errors if we have any.
     if (!empty($update_errors)) {
         foreach ($update_errors as $update_error) {
             wpcf_admin_message_store($update_error->get_error_message(), 'error');
         }
         wpcf_admin_message_store(sprintf('<strong>%s</strong>', __('There has been a problem while saving custom fields. Please fix it and try again.', 'wpcf')), 'error');
     }
 }
コード例 #8
0
 /**
  * Add a column for each term field on the term listing page.
  *
  * @param string[string] $columns Column definitions (column name => display name).
  * @return string[string] Updated column definitions.
  * @link https://make.wordpress.org/docs/plugin-developer-handbook/10-plugin-components/custom-list-table-columns/
  * @since 1.9.1
  */
 public function manage_term_listing_columns($columns)
 {
     $taxonomy_slug = wpcf_getget('taxonomy');
     $groups = WPCF_Field_Group_Term_Factory::get_instance()->get_groups_by_taxonomy($taxonomy_slug);
     $columns_to_insert = array();
     foreach ($groups as $group) {
         foreach ($group->get_field_definitions() as $field_definition) {
             $columns_to_insert[self::LISTING_COLUMN_PREFIX . $field_definition->get_slug()] = $field_definition->get_display_name();
         }
     }
     // Insert before the last column, which displays counts of posts using the term (that's probably why column
     // has the label "Count" and name "posts" :-P).
     $columns = WPCF_Utils::insert_at_position($columns, $columns_to_insert, array('key' => 'posts', 'where' => 'before'));
     return $columns;
 }