/** * 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(); }
/** * 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>'; } }
/** * 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); }