/**
  * 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 = '', $status = 'draft')
 {
     // 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_Post_Factory::get_instance()->create_field_group($name, $title, $status);
 }
Пример #2
0
 /**
  * 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.');
     }
 }
Пример #3
0
 private function new_post_field_group_action($type)
 {
     $type_object = get_post_type_object($type);
     $title = sprintf(__('Field Group for %s', 'types'), $type_object->labels->name);
     $name = sanitize_title($title);
     $new_post_field_group = Types_Field_Group_Post_Factory::get_instance()->create($name, $title, 'publish');
     if (!$new_post_field_group) {
         return false;
     }
     $new_post_field_group->assign_post_type($type);
     $url = isset($_GET['ref']) ? 'admin.php?page=wpcf-edit&group_id=' . $new_post_field_group->get_id() . '&ref=' . sanitize_text_field($_GET['ref']) : 'admin.php?page=wpcf-edit&group_id=' . $new_post_field_group->get_id();
     return admin_url($url);
 }
 /**
  * @inheritdoc
  * @return Types_Field_Group_Post_Factory
  * @since 2.0
  */
 public function get_group_factory()
 {
     return Types_Field_Group_Post_Factory::get_instance();
 }