/**
  * Initiate the dashboard metaboxes.
  *
  * @access private
  * @since  0.8
  *
  * @return void
  */
 public static function init()
 {
     // Bail if doing an AJAX request.
     if (defined('DOING_AJAX') && DOING_AJAX) {
         return;
     }
     // Build the array that defines the dashboard metaboxes.
     self::register();
     // Register the dashboard metaboxes the Metabox API.
     foreach (self::$metaboxes as $atts) {
         cnMetaboxAPI::add($atts);
     }
 }
 /**
  * Initiate the core metaboxes and fields.
  *
  * @access private
  * @since  0.8
  *
  * @return void
  */
 public static function init()
 {
     // Grab an instance of the Connections object.
     $instance = Connections_Directory();
     // Build the array that defines the core metaboxes.
     self::register();
     // Register the core metaboxes the Metabox API.
     foreach (self::$metaboxes as $atts) {
         cnMetaboxAPI::add($atts);
     }
     // Set the "Visibility" options that can be set by the current user.
     if (is_user_logged_in()) {
         self::$visibility = $instance->options->getVisibilityOptions();
     }
 }
 /**
  * Use to render the registered metaboxes on the frontend.
  * NOTE: To render the metaboxes on an admin page use do_meta_boxes().
  *
  * Accepted option for the $atts property are:
  * 	id (array) The metabox ID to render.
  * 	order (array) An indexed array of metabox IDs that should be rendered in the order in the array.
  * 		NOTE: Any registered metabox ID not supplied in `order` means `exclude` is implied.
  * 	exclude (array) An indexed array of metabox IDs that should be excluded from being rendered.
  * 	include (array) An indexed array of metabox IDs that should be rendered.
  * 		NOTE: Metabox IDs in `exclude` outweigh metabox IDs in include. Meaning if the same metabox ID
  * 		exists in both, the metabox will be excluded.
  *
  * @access public
  * @since 0.8
  * @param  array  $atts   The attributes array.
  * @param  object $object An instance the the cnEntry object.
  *
  * @return string         The HTML output of the registered metaboxes.
  */
 public static function metaboxes(array $atts = array(), $object)
 {
     $metaboxes = array();
     $defaults = array('id' => '', 'order' => array(), 'exclude' => array(), 'include' => array(), 'hide' => array());
     $atts = wp_parse_args($atts, $defaults);
     if (!empty($atts['id'])) {
         $metaboxes[$atts['id']] = cnMetaboxAPI::get($atts['id']);
     } else {
         if (!empty($atts['order'])) {
             // If the metabox order has been supplied, sort them as supplied. Exclude is implied.
             // Meaning, if a metabox ID is not supplied in $atts['order'], they will be excluded.
             foreach ($atts['order'] as $id) {
                 $metaboxes[$id] = cnMetaboxAPI::get($id);
             }
         } else {
             $metaboxes = cnMetaboxAPI::get();
         }
     }
     foreach ($metaboxes as $id => $metabox) {
         // Since custom metaboxes can be enabled/disabled, there's a possibility that there will
         // be a saved metabox in the settings that no longer exists. Lets catch this and continue.
         if (empty($metabox)) {
             continue;
         }
         // Exclude/Include the metaboxes that have been requested to exclude/include.
         if (!empty($atts['exclude'])) {
             if (in_array($id, $atts['exclude']) && !in_array($id, $atts['hide'])) {
                 continue;
             }
         } else {
             if (!empty($atts['include'])) {
                 if (!in_array($id, $atts['include']) && !in_array($id, $atts['hide'])) {
                     continue;
                 }
             }
         }
         $display = in_array($id, $atts['hide']) ? 'none' : 'block';
         echo '<div id="cn-metabox-' . $metabox['id'] . '" class="cn-metabox" style="display: ' . $display . '">';
         echo '<h3 class="cn-metabox-title">' . $metabox['title'] . '</h3>';
         echo '<div class="cn-metabox-inside">';
         if (is_callable($metabox['callback'])) {
             call_user_func($metabox['callback'], $object, $metabox);
         } else {
             if (is_string($metabox['callback'])) {
                 $callback = $metabox['callback'];
             } else {
                 if (is_array($metabox['callback'])) {
                     if (is_object($metabox['callback'][0])) {
                         $callback = get_class($metabox['callback'][0]) . '::' . $metabox['callback'][1];
                     } else {
                         $callback = implode('::', $metabox['callback']);
                     }
                 }
             }
             echo '<p>', __(sprintf('Invalid callback: %s', $callback), 'connections'), '</p>';
         }
         echo '<div class="cn-clear"></div>';
         echo '</div>';
         echo '</div>';
     }
 }
Esempio n. 4
0
 /**
  * Registers the entry edit form metaboxes.
  *
  * This is deprecated method, left in place for backward compatibility only.
  *
  * NOTE: This should only be called by the "load-$page_hook" action.
  *
  * @access private
  * @deprecated
  * @since 0.8
  * @param string  $pageHook The page hook to add the entry edit metaboxes to.
  * @return void
  */
 public function registerEditMetaboxes($pageHook)
 {
     // Retrieve all metabox registered with cnMetaboxAPI.
     $metaboxes = cnMetaboxAPI::get();
     foreach ($metaboxes as $metabox) {
         $metabox['pages'] = array($pageHook);
         cnMetaboxAPI::add($metabox);
     }
     cnMetaboxAPI::register();
 }
Esempio n. 5
0
function cn_register_custom_bio_and_text_field()
{
    $atts = array('title' => 'biog-highlights', 'id' => 'highlights_one', 'context' => 'normal', 'priority' => 'core', 'fields' => array(array('name' => 'Biography', 'show_label' => TRUE, 'id' => 'highlights_id', 'type' => 'text', 'size' => 'regular')));
    cnMetaboxAPI::add($atts);
}
 /**
  * Registered the custom metabox.
  *
  * @access private
  * @since  1.0
  * @static
  * @uses   levels()
  * @uses   cnMetaboxAPI::add()
  * @return void
  */
 public static function registerMetabox()
 {
     $atts = array('name' => __('Hobbies', 'connections_hobbies'), 'id' => 'hobbies', 'title' => __('Hobbies', 'connections_hobbies'), 'context' => 'side', 'priority' => 'core', 'fields' => array(array('id' => 'hobbies', 'type' => 'checkbox-group', 'options' => self::hobbies(), 'default' => '')));
     cnMetaboxAPI::add($atts);
 }
 /**
  * Checks whether or not the `key` is private or not.
  *
  * @access public
  * @since  0.8
  *
  * @param  string $key  The key to check.
  * @param  string $type The object type.
  *
  * @return boolean
  */
 public static function isPrivate($key, $type = NULL)
 {
     $private = FALSE;
     if (is_string($key) && strlen($key) > 0) {
         $private = '_' == $key[0];
         // Grab the registered metaboxes from the options table.
         // $metaboxes = get_option( 'connections_metaboxes', array() );
         $metaboxes = cnMetaboxAPI::get();
         // Loop thru all fields registered as part of a metabox.
         // If one id found consider it private and exit the loops.
         //
         // NOTE: All fields registered via the metabox  API are considered private.
         // The expectation is an action will be called to render the metadata.
         foreach ($metaboxes as $metabox) {
             if (isset($metabox['fields'])) {
                 foreach ($metabox['fields'] as $field) {
                     if ($field['id'] == $key) {
                         // Field found, it's private ... exit loop.
                         $private = TRUE;
                         continue;
                     }
                 }
             }
             if (isset($metabox['sections'])) {
                 foreach ($metabox['sections'] as $section) {
                     foreach ($section['fields'] as $field) {
                         if ($field['id'] == $key) {
                             // Field found, it's private ... exit the loops.
                             $private = TRUE;
                             continue 2;
                         }
                     }
                 }
             }
         }
     }
     return apply_filters('cn_is_private_meta', $private, $key, $type);
 }