Defines the key container methods and their default implementations.
 /**
  * Create a new user meta container
  *
  * @param string $title Unique title of the container
  **/
 public function __construct($title)
 {
     parent::__construct($title);
     if (!$this->get_datastore()) {
         $this->set_datastore(new User_Meta_Datastore());
     }
 }
 /**
  * Revert the result of attach()
  **/
 public function detach()
 {
     parent::detach();
     remove_action('admin_init', array($this, '_attach'));
     remove_action('edit_comment', array($this, '_save'));
     // unregister field names
     foreach ($this->fields as $field) {
         $this->drop_unique_field_name($field->get_name());
     }
 }
Пример #3
0
 /**
  * Outputs the settings update form.
  *
  * @param array $instance Current settings.
  */
 public function form($instance)
 {
     $this->store_data = $instance;
     $custom_fields = array();
     foreach ($this->custom_fields as $field) {
         $tmp_field = clone $field;
         $tmp_field->load();
         $field_name = $this->get_field_name($tmp_field->get_name());
         $tmp_field->set_name($field_name);
         $custom_fields[] = $tmp_field;
     }
     Container::factory('widget', $this->id)->add_fields($custom_fields)->init();
 }
    public function create_options_page($page_parent = '')
    {
        if (!class_exists('\\Carbon_Fields\\Container\\Container')) {
            return;
        }
        Container::make('theme_options', __('Instagram Settings', 'crb'))->set_page_parent($page_parent)->add_fields(array(Field::make('html', 'crb_instagram_settings_html')->set_html('
						<div style="position: relative; background: #fff; border: 1px solid #ccc; padding: 10px;">
							<h4><strong>' . __('Instagram API requires an Instagram client for communication with 3rd party sites. Here are the steps for creating and setting up an Instagram client:', 'crb') . '</strong></h4>
							<ol style="font-weight: normal; margin-left: 25px;">
								<li>' . sprintf(__('Go to <a href="%1$s" target="_blank">%1$s</a> and log in, if necessary.', 'crb'), 'https://instagram.com/developer/clients/register/') . '</li>
								<li>' . __('Supply the necessary required fields. <strong>Valid redirect URIs</strong> field must be filled with the value from the <strong>Redirect URI</strong> field below.', 'crb') . '</li>
								<li>' . __('Click the Register button.', 'crb') . '</li>
								<li>' . __('On the next screen, copy the following fields: <strong>Client ID, Client Secret</strong> to the below fields.', 'crb') . '</li>
								<li>' . __('Save the updates using the "Save Changes" button on this page', 'crb') . '</li>
								<li>' . __('Click the "Authenticate" button and follow the on screen instructions.', 'crb') . '</li>
							</ol>
						</div>
					'), Field::make('text', $this->client->carbon_config_fields['user_name'], __('Username', 'crb')), Field::make('textarea', $this->client->carbon_config_fields['hashtags'], __('Hashtags', 'crb'))->set_help_text(__('Separate hashtags with a comma.', 'crb')), Field::make('text', $this->client->carbon_config_fields['client_id'], __('Client ID', 'crb'))->set_width(50), Field::make('text', $this->client->carbon_config_fields['client_secret'], __('Client Secret', 'crb'))->set_width(50), Field::make('text', $this->client->carbon_config_fields['redirect_uri'], __('Redirect URI', 'crb'))->set_default_value($this->client->get_redirect_uri()), Field::make('html', 'crb_instragram_authenticate')->set_html($this->generate_page_buttons())));
    }
 /**
  * Render attribute prevents field containers showing on menu save
  */
 public static function set_instance_for_id($current_menu_item_id, $render = true)
 {
     $active_containers = self::get_containers();
     $suffix = '-' . $current_menu_item_id;
     foreach ($active_containers as $container) {
         if ($container->type != 'Nav_Menu') {
             continue;
         }
         $custom_fields = array();
         $fields = $container->get_fields();
         foreach ($fields as $field) {
             $tmp_field = clone $field;
             // Setup Public properties
             $tmp_field->current_menu_item_id = $current_menu_item_id;
             $tmp_field->initial_name = $tmp_field->get_name();
             // Setup Field ID and Name
             $tmp_field->set_id($tmp_field->get_id() . $suffix);
             $tmp_field->set_name($tmp_field->get_name() . $suffix);
             // Update Datastore instance
             $new_datastore = new Nav_Menu_Datastore();
             $new_datastore->set_id($current_menu_item_id);
             $tmp_field->set_datastore($new_datastore);
             $custom_fields[] = $tmp_field;
         }
         self::$instances[$current_menu_item_id] = Container::factory('nav_menu', $container->id . $suffix)->add_fields($custom_fields)->init($current_menu_item_id, $render);
     }
     return self::$instances[$current_menu_item_id];
 }
Пример #6
0
 /**
  * Append array of fields to the current fields set. All items of the array
  * must be instances of Field and their names should be unique for all
  * Carbon containers.
  * If a field does not have DataStore already, the container data store is
  * assigned to them instead.
  *
  * @param array $fields
  **/
 public function add_fields($fields)
 {
     parent::add_fields($fields);
     foreach ($this->fields as $field) {
         $field->set_prefix('');
     }
     return $this;
 }
 /**
  * @covers Carbon_Fields\Container\Post_Meta_Container::show_on_template
  */
 public function testShowOnTemplateArrayResultPostType()
 {
     $container = Container::make('post_meta', $this->containerTitle);
     $container->show_on_template(array('default'));
     $this->assertSame(array('page'), $container->settings['post_type']);
 }
 /**
  * Revert the result of attach()
  *
  **/
 public function detach()
 {
     parent::detach();
     remove_action('admin_init', array($this, '_attach'));
     foreach ($this->settings['taxonomy'] as $taxonomy) {
         remove_action('edited_' . $taxonomy, array($this, '_save'), 10);
         remove_action('created_' . $taxonomy, array($this, '_save'), 10);
     }
     // unregister field names
     foreach ($this->fields as $field) {
         $this->drop_unique_field_name($field->get_name());
     }
 }
Пример #9
0
 /**
  * Retrieve containers and sidebars for use in the JS.
  *
  * @return array $carbon_data
  */
 public function get_json_data()
 {
     global $wp_registered_sidebars;
     $carbon_data = array('containers' => array(), 'sidebars' => array());
     $containers = Container::get_active_containers();
     foreach ($containers as $container) {
         $container_data = $container->to_json(true);
         $carbon_data['containers'][] = $container_data;
     }
     foreach ($wp_registered_sidebars as $sidebar) {
         // Check if we have inactive sidebars
         if (isset($sidebar['class']) && strpos($sidebar['class'], 'inactive-sidebar') !== false) {
             continue;
         }
         $carbon_data['sidebars'][] = array('name' => $sidebar['name'], 'id' => $sidebar['id']);
     }
     return $carbon_data;
 }
Пример #10
0
 /**
  * A proxy for the abstract container factory method.
  *
  * @see Carbon_Fields\Container\Container::factory()
  **/
 public static function factory($type, $name)
 {
     return Abstract_Container::factory($type, $name);
 }
 /**
  * @covers Carbon_Fields\Container\Container::make
  * @covers Carbon_Fields\Container\Container::factory
  * @covers Carbon_Fields\Container\Container::__construct
  */
 public function testContainerTypeCustomFieldsBackwardsCompatibility()
 {
     $container = Container::make('custom_fields', $this->containerTitle);
     $this->assertInstanceOf('Carbon_Fields\\Container\\Post_Meta_Container', $container);
 }