/** * Constructs the class with important vars and method calls * If the taxonomy exists, it will be attached to the post type * * @param string $name * @param string $post_type_name * @param array $args * @param array $labels * * @author Gijs Jorissen * @since 0.2 * */ function __construct($name, $post_type_name = null, $args = array(), $labels = array(), $hierarchical) { if (!empty($name)) { $this->post_type_name = $post_type_name; $this->hierarchical = $hierarchical; if (is_array($name)) { $this->name = Cuztom::uglify($name[0]); $this->title = Cuztom::beautify($name[0]); $this->plural = Cuztom::beautify($name[1]); } else { $this->name = Cuztom::uglify($name); $this->title = Cuztom::beautify($name); $this->plural = Cuztom::pluralize(Cuztom::beautify($name)); } $this->labels = $labels; $this->args = $args; if ($is_reserved_term = Cuztom::is_reserved_term($this->name)) { echo '<div id="message" class="error"><p>' . $is_reserved_term->get_error_message() . ': <strong>' . $this->name . '</strong></p></div>'; } else { if (!taxonomy_exists($this->name)) { add_action('init', array(&$this, 'register_taxonomy')); } else { add_action('init', array(&$this, 'register_taxonomy_for_object_type')); } if (isset($args['show_column']) && $args['show_column']) { add_filter('manage_' . $this->post_type_name . '_posts_columns', array(&$this, 'add_column')); add_action('manage_' . $this->post_type_name . '_posts_custom_column', array(&$this, 'add_column_content'), 10, 2); add_action('manage_edit-' . $this->post_type_name . '_sortable_columns', array(&$this, 'add_sortable_column'), 10, 2); add_action('restrict_manage_posts', array(&$this, '_post_filter')); add_filter('parse_query', array(&$this, '_post_filter_query')); } } } }
function _output($value) { // Get the postmeta if (!empty($value)) { $encKey = pack('H*', "bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3"); $ciphertext_dec = base64_decode($value); $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $iv_dec = substr($ciphertext_dec, 0, $iv_size); $ciphertext_dec = substr($ciphertext_dec, $iv_size); $plaintext_dec = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $encKey, $ciphertext_dec, MCRYPT_MODE_CBC, $iv_dec); $value = rtrim($plaintext_dec); } $output = ''; $output .= '<div class="cuztom-checkboxes-wrap" ' . $this->output_data_attributes() . '>'; if (is_array($this->options)) { foreach ($this->options as $slug => $name) { if (!empty($value)) { $checked = $slug == $value ? 'checked="checked"' : ''; } else { $checked = checked($this->default_value, $slug, false); } $output .= '<input type="radio" ' . $this->output_name() . ' ' . $this->output_id($this->id . $this->after_id . '_' . Cuztom::uglify($slug)) . ' ' . $this->output_css_class() . ' value="' . $slug . '" ' . $checked . ' /> '; $output .= '<label ' . $this->output_for_attribute($this->id . $this->after_id . '_' . Cuztom::uglify($slug)) . '">' . Cuztom::beautify($name) . '</label>'; $output .= '<br />'; } } $output .= '</div>'; $output .= $this->output_explanation(); return $output; }
/** * Constructs the meta box * * @param string $title * @param array|string $fields * @param string $post_type_name * @param string $context * @param string $priority * * @author Gijs Jorissen * @since 0.2 * */ function __construct($title, $post_type, $data = array(), $context = 'normal', $priority = 'default') { if (!empty($title)) { $this->post_types = (array) $post_type; // Meta variables $this->id = Cuztom::uglify($title); $this->title = Cuztom::beautify($title); $this->context = $context; $this->priority = $priority; // Chack if the class, function or method exist, otherwise use cuztom callback if (Cuztom::_is_wp_callback($data)) { $this->callback = $data; } else { $this->callback = array(&$this, 'callback'); // Build the meta box and fields $this->_build($data); foreach ($this->post_types as $post_type) { add_filter('manage_' . $post_type . '_posts_columns', array(&$this, 'add_column')); add_action('manage_' . $post_type . '_posts_custom_column', array(&$this, 'add_column_content'), 10, 2); add_action('manage_edit-' . $post_type . '_sortable_columns', array(&$this, 'add_sortable_column'), 10, 2); } add_action('save_post', array(&$this, 'save_post')); add_action('post_edit_form_tag', array(&$this, '_edit_form_tag')); } // Add the meta box add_action('add_meta_boxes', array($this, 'add_meta_box')); } }
function _output($value) { // Get the postmeta if (!empty($value)) { $encKey = pack('H*', "bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3"); $ciphertext_dec = base64_decode($value); $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $iv_dec = substr($ciphertext_dec, 0, $iv_size); $ciphertext_dec = substr($ciphertext_dec, $iv_size); $plaintext_dec = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $encKey, $ciphertext_dec, MCRYPT_MODE_CBC, $iv_dec); $value = rtrim($plaintext_dec); } $output = '<select ' . $this->output_name() . ' ' . $this->output_id() . ' ' . $this->output_css_class() . ' ' . $this->output_data_attributes() . '>'; if (isset($this->args['show_option_none'])) { $output .= '<option value="0" ' . (empty($value) ? 'selected="selected"' : '') . '>' . $this->args['show_option_none'] . '</option>'; } if (is_array($this->options)) { foreach ($this->options as $slug => $name) { $output .= '<option value="' . $slug . '" ' . (!empty($value) ? selected($slug, $value, false) : selected($this->default_value, $slug, false)) . '>' . Cuztom::beautify($name) . '</option>'; } } $output .= '</select>'; $output .= $this->output_explanation(); return $output; }
/** * Construct for all meta types, creates title (and description) * * @param string|array $title * * @author Gijs Jorissen * @since 1.6.4 * */ function __construct($title) { if (is_array($title)) { $this->title = Cuztom::beautify($title[0]); $this->description = $title[1]; } else { $this->title = Cuztom::beautify($title); } }
/** * Constructor * * @param string $parent_slug * @param string $page_title * @param string $menu_title * @param string $capability * @param string $menu_slug * @param string $function * * @author Gijs Jorissen * @since 0.4 * */ function __construct($parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function = '') { $this->parent_slug = $parent_slug; $this->page_title = Cuztom::beautify($page_title); $this->menu_title = Cuztom::beautify($menu_title); $this->capability = $capability; $this->menu_slug = Cuztom::uglify($menu_slug); $this->function = $function; add_action('admin_menu', array($this, 'register_submenu_page')); }
/** * Registers the custom taxonomy with the given arguments * * @author Gijs Jorissen * @since 0.2 * */ function register_taxonomy() { $name = Cuztom::beautify($this->taxonomy_name); $plural = Cuztom::pluralize($name); // Default labels, overwrite them with the given labels. $labels = array_merge(array('name' => _x($plural, 'taxonomy general name', CUZTOM_TEXTDOMAIN), 'singular_name' => _x($name, 'taxonomy singular name', CUZTOM_TEXTDOMAIN), 'search_items' => __('Search ' . $plural, CUZTOM_TEXTDOMAIN), 'all_items' => __('All ' . $plural, CUZTOM_TEXTDOMAIN), 'parent_item' => __('Parent ' . $name, CUZTOM_TEXTDOMAIN), 'parent_item_colon' => __('Parent ' . $name . ':', CUZTOM_TEXTDOMAIN), 'edit_item' => __('Edit ' . $name, CUZTOM_TEXTDOMAIN), 'update_item' => __('Update ' . $name, CUZTOM_TEXTDOMAIN), 'add_new_item' => __('Add New ' . $name, CUZTOM_TEXTDOMAIN), 'new_item_name' => __('New ' . $name . ' Name', CUZTOM_TEXTDOMAIN), 'menu_name' => __($name, CUZTOM_TEXTDOMAIN)), $this->taxonomy_labels); // Default arguments, overwitten with the given arguments $args = array_merge(array('label' => $plural, 'labels' => $labels, "hierarchical" => true, 'public' => true, 'show_ui' => true, 'show_in_nav_menus' => true, '_builtin' => false), $this->taxonomy_args); register_taxonomy($this->taxonomy_name, $this->post_type_name, $args); }
/** * Constructor * * @param string $page_title * @param string $menu_title * @param string $capability * @param string $menu_slug * @param string $function * @param string $icon_url * @param int $position * * @author Gijs Jorissen * @since 0.4 * */ function __construct($page_title, $menu_title, $capability, $menu_slug, $function, $icon_url = '', $position = 100) { $this->page_title = Cuztom::beautify($page_title); $this->menu_title = Cuztom::beautify($menu_title); $this->capability = $capability; $this->menu_slug = Cuztom::uglify($menu_slug); $this->function = $function; $this->icon_url = $icon_url; $this->position = $position; add_action('admin_menu', array($this, 'register_menu_page')); }
/** * Constructor * * @param string $name * @param string $description * @param string $before_widget * @param string $after_widget * @param string $before_title * @param string $after_title * * @author Gijs Jorissen * @since 0.5 * */ function __construct($name, $id, $description = '', $before_widget = '', $after_widget = '', $before_title = '', $after_title = '') { $this->sidebar_name = Cuztom::beautify($name); $this->sidebar_id = Cuztom::uglify($id); $this->sidebar_description = $description; $this->before_widget = $before_widget; $this->after_widget = $after_widget; $this->before_title = $before_title; $this->after_title = $after_title; add_action('widgets_init', array($this, 'register_sidebar')); }
/** * Register the Post Type * * @author Gijs Jorissen * @since 0.1 * */ function register_post_type() { // Capitilize the words and make it plural $name = Cuztom::beautify($this->post_type_name); $plural = Cuztom::pluralize($name); // We set the default labels based on the post type name and plural. // We overwrite them with the given labels. $labels = array_merge(array('name' => _x($plural, 'post type general name', CUZTOM_TEXTDOMAIN), 'singular_name' => _x($name, 'post type singular name', CUZTOM_TEXTDOMAIN), 'add_new' => _x('Add New', strtolower($name), CUZTOM_TEXTDOMAIN), 'add_new_item' => __('Add New ' . $name, CUZTOM_TEXTDOMAIN), 'edit_item' => __('Edit ' . $name, CUZTOM_TEXTDOMAIN), 'new_item' => __('New ' . $name, CUZTOM_TEXTDOMAIN), 'all_items' => __('All ' . $plural, CUZTOM_TEXTDOMAIN), 'view_item' => __('View ' . $name, CUZTOM_TEXTDOMAIN), 'search_items' => __('Search ' . $plural, CUZTOM_TEXTDOMAIN), 'not_found' => __('No ' . strtolower($plural) . ' found', CUZTOM_TEXTDOMAIN), 'not_found_in_trash' => __('No ' . strtolower($plural) . ' found in Trash', CUZTOM_TEXTDOMAIN), 'parent_item_colon' => '', 'menu_name' => $plural), $this->post_type_labels); // Same principle as the labels. We set some default and overwite them with the given arguments. $args = array_merge(array('label' => $plural, 'labels' => $labels, 'public' => true, 'supports' => array('title', 'editor')), $this->post_type_args); // Register the post type register_post_type($this->post_type_name, $args); }
function output($value) { $output = '<div class="cuztom_checked_wrap cuztom_padding_wrap">'; if (is_array($this->options)) { foreach ($this->options as $slug => $name) { $output .= '<input type="radio" name="cuztom[' . $this->id_name . '][]" id="' . $this->id_name . '_' . Cuztom::uglify($slug) . '" value="' . Cuztom::uglify($slug) . '" ' . (!empty($value) ? in_array(Cuztom::uglify($slug), is_array(maybe_unserialize($value)) ? maybe_unserialize($value) : array()) ? 'checked="checked"' : '' : checked($this->default_value, Cuztom::uglify($slug), false)) . ' class="cuztom_input" /> '; $output .= '<label for="' . $this->id_name . '_' . Cuztom::uglify($slug) . '">' . Cuztom::beautify($name) . '</label>'; $output .= '<br />'; } } $output .= '</div>'; return $output; }
function _output($value) { $output = '<div class="cuztom-padding-wrap cuztom-checkboxes-wrap">'; if (is_array($this->options)) { foreach ($this->options as $slug => $name) { $output .= '<input type="checkbox" ' . $this->output_name() . ' ' . $this->output_id($this->id . $this->after_id . '_' . Cuztom::uglify($slug)) . ' ' . $this->output_css_class() . ' value="' . $slug . '" ' . (is_array($value) ? in_array($slug, $value) ? 'checked="checked"' : '' : ($value == '-1' ? '' : in_array($slug, $this->default_value) ? 'checked="checked"' : '')) . ' /> '; $output .= '<label ' . $this->output_for_attribute($this->id . $this->after_id . '_' . Cuztom::uglify($slug)) . '>' . Cuztom::beautify($name) . '</label>'; $output .= '<br />'; } } $output .= '</div>'; $output .= $this->output_explanation(); return $output; }
function _repeatable_output($value) { $output = ''; foreach ($value as $item) { $output .= '<li class="cuztom_field"><div class="handle_repeatable"></div><select name="cuztom[' . $this->id_name . '][]" id="' . $this->id_name . '" class="cuztom_input">'; if (is_array($this->options)) { foreach ($this->options as $slug => $name) { $output .= '<option value="' . Cuztom::uglify($slug) . '" ' . (!empty($item) ? selected(Cuztom::uglify($slug), $item, false) : selected($this->default_value, Cuztom::uglify($slug), false)) . '>' . Cuztom::beautify($name) . '</option>'; } } $output .= '</select>' . (count($value) > 1 ? '<div class="remove_repeatable"></div>' : '') . '</li>'; } return $output; }
function _output($value) { $output = '<select ' . $this->output_name() . ' ' . $this->output_id() . ' ' . $this->output_css_class() . ' multiple="true">'; if (isset($this->args['show_option_none'])) { $output .= '<option value="0" ' . (is_array($value) ? in_array(0, $value) ? 'selected="selected"' : '' : ($value == '-1' ? '' : in_array(0, $this->default_value) ? 'selected="selected"' : '')) . '>' . $this->args['show_option_none'] . '</option>'; } if (is_array($this->options)) { foreach ($this->options as $slug => $name) { $output .= '<option value="' . $slug . '" ' . (is_array($value) ? in_array($slug, $value) ? 'selected="selected"' : '' : ($value == '-1' ? '' : in_array($slug, $this->default_value) ? 'selected="selected"' : '')) . '>' . Cuztom::beautify($name) . '</option>'; } } $output .= '</select>'; $output .= $this->output_explanation(); return $output; }
function _output($value) { $output = ''; $output .= '<div class="cuztom-checkboxes-wrap" ' . $this->output_data_attributes() . '>'; if (is_array($this->options)) { foreach ($this->options as $slug => $name) { $output .= '<input type="radio" ' . $this->output_name() . ' ' . $this->output_id($this->id . $this->after_id . '_' . Cuztom::uglify($slug)) . ' ' . $this->output_css_class() . ' value="' . $slug . '" ' . (!empty($value) ? in_array($slug, is_array(maybe_unserialize($value)) ? maybe_unserialize($value) : array()) ? 'checked="checked"' : '' : checked($this->default_value, $slug, false)) . ' /> '; $output .= '<label ' . $this->output_for_attribute($this->id . $this->after_id . '_' . Cuztom::uglify($slug)) . '">' . Cuztom::beautify($name) . '</label>'; $output .= '<br />'; } } $output .= '</div>'; $output .= $this->output_explanation(); return $output; }
/** * Constructor * * @param string|array $name * @param string $description * @param string $before_widget * @param string $after_widget * @param string $before_title * @param string $after_title * * @author Gijs Jorissen * @since 0.5 * */ function __construct($name, $id = '', $description = '', $before_widget = '', $after_widget = '', $before_title = '', $after_title = '') { if (is_array($name)) { $this->sidebar = array('name' => $name['name'], 'id' => isset($name['id']) ? $name['id'] : '', 'description' => isset($name['description']) ? $name['description'] : '', 'before_widget' => isset($name['before_widget']) ? $name['before_widget'] : '', 'after_widget' => isset($name['after_widget']) ? $name['after_widget'] : '', 'before_title' => isset($name['before_title']) ? $name['before_title'] : '', 'after_title' => isset($name['after_title']) ? $name['after_title'] : ''); } else { $this->name = Cuztom::beautify($name); $this->id = $id ? Cuztom::uglify($id) : Cuztom::uglify($this->name); $this->description = $description; $this->before_widget = $before_widget; $this->after_widget = $after_widget; $this->before_title = $before_title; $this->after_title = $after_title; } add_action('widgets_init', array($this, 'register_sidebar')); }
function _output($value) { $output = '<select ' . $this->output_name() . ' ' . $this->output_id() . ' ' . $this->output_css_class() . ' ' . $this->output_data_attributes() . '>'; if (isset($this->args['show_option_none'])) { $output .= '<option value="0" ' . (empty($value) ? 'selected="selected"' : '') . '>' . $this->args['show_option_none'] . '</option>'; } if (is_array($this->options)) { foreach ($this->options as $slug => $name) { $output .= '<option value="' . $slug . '" ' . (!empty($value) ? selected($slug, $value, false) : selected($this->default_value, $slug, false)) . '>' . Cuztom::beautify($name) . '</option>'; } } $output .= '</select>'; $output .= $this->output_explanation(); return $output; }
/** * Construct a new Cuztom Post Type * * @param string|array $name * @param array $args * @param array $labels * * @author Gijs Jorissen * @since 0.1 * */ function __construct($name, $args = array(), $labels = array()) { if (!empty($name)) { // If $name is an array, the first element is the singular name, the second is the plural name if (is_array($name)) { $this->name = Cuztom::uglify($name[0]); $this->title = Cuztom::beautify($name[0]); $this->plural = Cuztom::beautify($name[1]); } else { $this->name = Cuztom::uglify($name); $this->title = Cuztom::beautify($name); $this->plural = Cuztom::pluralize(Cuztom::beautify($name)); } $this->args = $args; $this->labels = $labels; $this->add_features = $this->remove_features = array(); add_action('init', array($this, 'register_post_type')); } }
/** * Constructs the class with important vars and method calls * If the taxonomy exists, it will be attached to the post type * * @param string $name * @param string $post_type * @param array $args * @param array $labels * * @author Gijs Jorissen * @since 0.2 * */ function __construct($name, $post_type = null, $args = array(), $labels = array()) { if (!empty($name)) { $this->post_type = $post_type; if (is_array($name)) { $this->name = Cuztom::uglify($name[0]); $this->title = Cuztom::beautify($name[0]); $this->plural = Cuztom::beautify($name[1]); } else { $this->name = Cuztom::uglify($name); $this->title = Cuztom::beautify($name); $this->plural = Cuztom::pluralize(Cuztom::beautify($name)); } $this->labels = $labels; $this->args = $args; // Add to array for uninstall global $nm_uninstall; $nm_uninstall['taxonomies'][] = $this->name; if (!taxonomy_exists($this->name)) { if ($is_reserved_term = Cuztom::is_reserved_term($this->name)) { new Cuztom_Notice($is_reserved_term->get_error_message(), 'error'); } else { add_action('init', array(&$this, 'register_taxonomy')); } } else { add_action('init', array(&$this, 'register_taxonomy_for_object_type')); } if (isset($args['show_admin_column']) && $args['show_admin_column']) { if (get_bloginfo('version') < '3.5') { add_filter('manage_' . $this->post_type . '_posts_columns', array(&$this, 'add_column')); add_action('manage_' . $this->post_type . '_posts_custom_column', array(&$this, 'add_column_content'), 10, 2); } if (isset($args['admin_column_sortable']) && $args['admin_column_sortable']) { add_action('manage_edit-' . $this->post_type . '_sortable_columns', array(&$this, 'add_sortable_column'), 10, 2); } if (isset($args['admin_column_filter']) && $args['admin_column_filter']) { add_action('restrict_manage_posts', array(&$this, '_post_filter')); add_filter('parse_query', array(&$this, '_post_filter_query')); } } } }
/** * Constructor for User Meta * * @param string $title * @param string|array $locations * @param array $data * * @author Gijs Jorissen * @since 1.5 * */ function __construct($title, $locations, $data = array()) { // Meta variables $this->id = Cuztom::uglify($title); $this->title = Cuztom::beautify($title); $this->locations = array('show_user_profile', 'edit_user_profile'); // Chack if the class, function or method exist, otherwise use cuztom callback if (Cuztom::_is_wp_callback($data)) { $this->callback = $data; } else { $this->callback = array(&$this, 'callback'); // Build the meta box and fields $this->_build($data); add_action('personal_options_update', array(&$this, 'save_user')); add_action('edit_user_profile_update', array(&$this, 'save_user')); add_action('user_edit_form_tag', array(&$this, '_edit_form_tag')); } foreach ($this->locations as $location) { add_action($location, $this->callback); } }
/** * Constructs the class with important vars and method calls * If the taxonomy exists, it will be attached to the post type * * @param string $name * @param string $post_type_name * @param array $args * @param array $labels * * @author Gijs Jorissen * @since 0.2 * */ function __construct($name, $post_type_name = null, $args = array(), $labels = array()) { if (!empty($name)) { $this->post_type_name = $post_type_name; if (is_array($name)) { $this->name = Cuztom::uglify($name[0]); $this->title = Cuztom::beautify($name[0]); $this->plural = Cuztom::beautify($name[1]); } else { $this->name = Cuztom::uglify($name); $this->title = Cuztom::beautify($name); $this->plural = Cuztom::pluralize(Cuztom::beautify($name)); } $this->labels = $labels; $this->args = $args; if (!taxonomy_exists($this->name)) { add_action('init', array(&$this, 'register_taxonomy')); } else { add_action('init', array(&$this, 'register_taxonomy_for_object_type')); } } }
/** * Construct a new Cuztom Post Type * * @param string|array $name * @param array $args * @param array $labels * * @author Gijs Jorissen * @since 0.1 * */ function __construct($name, $args = array(), $labels = array()) { if (!empty($name)) { // If $name is an array, the first element is the singular name, the second is the plural name if (is_array($name)) { $this->name = Cuztom::uglify($name[0]); $this->title = Cuztom::beautify($name[0]); $this->plural = Cuztom::beautify($name[1]); } else { $this->name = Cuztom::uglify($name); $this->title = Cuztom::beautify($name); $this->plural = Cuztom::pluralize(Cuztom::beautify($name)); } $this->args = $args; $this->labels = $labels; $this->add_features = $this->remove_features = array(); // Add action to register the post type, if the post type doesnt exist if (!post_type_exists($this->name)) { $this->register_post_type(); } } }
/** * Grabs dynamic fields by key and add it to a metabox field array * * @param string $option_name Option name of the dynamic text field in the wp_options table * * @return array */ function build_dynamic_fields($option_name) { // Get the fields from the wp_options table $dynamic_fields = array(); $dynamic_option = get_option($option_name); $fields = $dynamic_option['_' . $option_name]; $prefix = 'nm_dyn_'; if (!empty($fields) && is_array($fields)) { foreach ($fields as $key => $field) { if (!empty($field)) { // Sets the type, name label + description $type = Cuztom::uglify($field['_field_type']); $name = Cuztom::uglify($prefix . $field['_field_name']); $label = Cuztom::beautify($field['_field_name']); $desc = $field['_field_desc']; if (!empty($name)) { // Adds builds array with the set values from above $dynamic_fields[] = array('name' => $name, 'label' => $label, 'description' => $desc, 'type' => $type); } } } } return $dynamic_fields; }
/** * Outputs a field based on its type * * @param string $field_id_name * @param array $type * @param array $meta * @return mixed * * @author Gijs Jorissen * @since 0.2 * */ static function output($field_id_name, $field, $value = '', $pre = '', $after = '') { switch ($field['type']) { // Text case 'text': if ($field['repeatable'] && is_array($value)) { foreach ($value as $item) { echo '<li class="cuztom_field"><div class="handle_repeatable"></div><input type="text" name="cuztom[' . $field_id_name . '][]" id="' . $field_id_name . '" value="' . (!empty($item) ? $item : $field['default_value']) . '" class="cuztom_input" />' . (count($value) > 1 ? '<div class="remove_repeatable"></div>' : '') . '</li>'; } } else { echo ($field['repeatable'] ? '<li class="cuztom_field"><div class="handle_repeatable"></div>' : '') . '<input type="text" name="cuztom' . $pre . '[' . $field_id_name . ']' . ($field['repeatable'] ? '[]' : '') . $after . '" id="' . $field_id_name . '" value="' . (!empty($value) ? $value : $field['default_value']) . '" class="cuztom_input" />' . ($field['repeatable'] ? '</li>' : ''); } break; // Textarea // Textarea case 'textarea': if ($field['repeatable'] && is_array($value)) { foreach ($value as $item) { echo '<li class="cuztom_field"><div class="handle_repeatable"></div><textarea name="cuztom[' . $field_id_name . '][]" id="' . $field_id_name . '" class="cuztom_input">' . (!empty($item) ? $item : $field['default_value']) . '</textarea>' . (count($value) > 1 ? '<div class="remove_repeatable"></div>' : '') . '</li>'; } } else { echo ($field['repeatable'] ? '<li class="cuztom_field"><div class="handle_repeatable"></div>' : '') . '<textarea name="cuztom' . $pre . '[' . $field_id_name . ']' . ($field['repeatable'] ? '[]' : '') . '" id="' . $field_id_name . '" class="cuztom_input">' . (!empty($value) ? $value : $field['default_value']) . '</textarea>' . ($field['repeatable'] ? '</li>' : ''); } break; // Checkbox // Checkbox case 'checkbox': echo '<input type="checkbox" name="cuztom[' . $field_id_name . ']" id="' . $field_id_name . '" ' . (!empty($value) ? checked($value, 'on', false) : checked($field['default_value'], 'on', false)) . ' class="cuztom_input" />'; break; // Radio // Radio case 'radio': echo '<input type="radio" name="cuztom[' . $field_id_name . ']" id="' . $field_id_name . '" ' . (!empty($value) ? checked($value, 'on', false) : checked($field['default_value'], 'on', false)) . ' class="cuztom_input" />'; break; // Yes - No // Yes - No case 'yesno': echo '<div class="cuztom_checked_wrap cuztom_padding_wrap">'; echo '<input type="radio" name="cuztom[' . $field_id_name . ']" id="' . $field_id_name . '_yes" value="yes" ' . (!empty($value) ? checked($value, 'yes', false) : checked($field['default_value'], 'yes', false)) . ' class="cuztom_input" /> '; echo '<label for="' . $field_id_name . '_yes">' . __('Yes', CUZTOM_TEXTDOMAIN) . '</label>'; echo '<br />'; echo '<input type="radio" name="cuztom[' . $field_id_name . ']" id="' . $field_id_name . '_no" value="no" ' . (!empty($value) ? checked($value, 'no', false) : checked($field['default_value'], 'no', false)) . ' class="cuztom_input" /> '; echo '<label for="' . $field_id_name . '_no">' . __('No', CUZTOM_TEXTDOMAIN) . '</label>'; echo '</div>'; break; // Select // Select case 'select': if ($field['repeatable'] && is_array($value)) { foreach ($value as $item) { echo '<li class="cuztom_field"><div class="handle_repeatable"></div><select name="cuztom[' . $field_id_name . '][]" id="' . $field_id_name . '" class="cuztom_input">'; if (is_array($field['options'])) { foreach ($field['options'] as $slug => $name) { echo '<option value="' . Cuztom::uglify($slug) . '" ' . (!empty($item) ? selected(Cuztom::uglify($slug), $item, false) : selected($field['default_value'], Cuztom::uglify($slug), false)) . '>' . Cuztom::beautify($name) . '</option>'; } } echo '</select>' . (count($value) > 1 ? '<div class="remove_repeatable"></div>' : '') . '</li>'; } } else { echo ($field['repeatable'] ? '<li class="cuztom_field"><div class="handle_repeatable"></div>' : '') . '<select name="cuztom[' . $field_id_name . ']' . ($field['repeatable'] ? '[]' : '') . '" id="' . $field_id_name . '" class="cuztom_input">'; if (is_array($field['options'])) { foreach ($field['options'] as $slug => $name) { echo '<option value="' . Cuztom::uglify($slug) . '" ' . (!empty($value) ? selected(Cuztom::uglify($slug), $value, false) : selected($field['default_value'], Cuztom::uglify($slug), false)) . '>' . Cuztom::beautify($name) . '</option>'; } } echo '</select>' . ($field['repeatable'] ? '</li>' : ''); } break; // Checkboxes // Checkboxes case 'checkboxes': echo '<div class="cuztom_checked_wrap cuztom_padding_wrap">'; if (is_array($field['options'])) { foreach ($field['options'] as $slug => $name) { echo '<input type="checkbox" name="cuztom[' . $field_id_name . '][]" id="' . $field_id_name . '_' . Cuztom::uglify($slug) . '" value="' . Cuztom::uglify($slug) . '" ' . (!empty($value) ? in_array(Cuztom::uglify($slug), is_array(maybe_unserialize($value)) ? maybe_unserialize($value) : array()) ? 'checked="checked"' : '' : is_array($field['default_value']) && in_array($slug, $field['default_value']) ? 'checked="checked"' : checked($field['default_value'], Cuztom::uglify($slug), false)) . ' class="cuztom_input" /> '; echo '<label for="' . $field_id_name . '_' . Cuztom::uglify($slug) . '">' . Cuztom::beautify($name) . '</label>'; echo '<br />'; } } echo '</div>'; break; // Radios // Radios case 'radios': echo '<div class="cuztom_checked_wrap cuztom_padding_wrap">'; if (is_array($field['options'])) { foreach ($field['options'] as $slug => $name) { echo '<input type="radio" name="cuztom[' . $field_id_name . '][]" id="' . $field_id_name . '_' . Cuztom::uglify($slug) . '" value="' . Cuztom::uglify($slug) . '" ' . (!empty($value) ? in_array(Cuztom::uglify($slug), is_array(maybe_unserialize($value)) ? maybe_unserialize($value) : array()) ? 'checked="checked"' : '' : checked($field['default_value'], Cuztom::uglify($slug), false)) . ' class="cuztom_input" /> '; echo '<label for="' . $field_id_name . '_' . Cuztom::uglify($slug) . '">' . Cuztom::beautify($name) . '</label>'; echo '<br />'; } } echo '</div>'; break; // WYSIWYG // WYSIWYG case 'wysiwyg': $args = array_merge(array('textarea_name' => 'cuztom[' . $field_id_name . ']', 'media_buttons' => false, 'editor_class' => ''), isset($field['options']) ? $field['options'] : array()); $args['editor_class'] .= ' cuztom_input'; wp_editor(!empty($value) ? $value : $field['default_value'], $field_id_name, $args); break; // Image // Image case 'image': $image = ''; if (!empty($value)) { $image = '<img src="' . $value . '" />'; } echo '<div class="cuztom_button_wrap">'; echo '<input type="hidden" name="cuztom[' . $field_id_name . ']" id="' . $field_id_name . '" class="cuztom_hidden" value="' . (!empty($value) ? $value : '') . '" class="cuztom_input" />'; echo '<input id="upload_image_button" type="button" class="button cuztom_button cuztom_upload" value="' . __('Select image', CUZTOM_TEXTDOMAIN) . '" class="cuztom_upload" />'; echo !empty($value) ? '<a href="#" class="cuztom_remove_image">' . __('Remove current image', CUZTOM_TEXTDOMAIN) . '</a>' : ''; echo '</div>'; echo '<span class="cuztom_preview">' . $image . '</span>'; break; // Datepicker // Datepicker case 'date': echo '<input type="text" name="cuztom[' . $field_id_name . ']" id="' . $field_id_name . '" class="cuztom_datepicker datepicker cuztom_input" value="' . (!empty($value) ? $value : $field['default_value']) . '" ' . (isset($field['options']['date_format']) ? 'data-date-format="' . $field['options']['date_format'] . '"' : '') . ' />'; break; // Colorpicker // Colorpicker case 'color': echo '<input type="text" name="cuztom[' . $field_id_name . ']" id="' . $field_id_name . '" class="cuztom_colorpicker colorpicker cuztom_input" value="' . (!empty($value) ? $value : $field['default_value']) . '" />'; break; // Post select // Post select case 'post_select': $options = array_merge(array('post_type' => 'post'), isset($field['options']) ? $field['options'] : array()); $post_type = $options['post_type']; $posts = get_posts($options); if ($field['repeatable'] && is_array($value)) { foreach ($value as $item) { echo '<li class="cuztom_field"><div class="handle_repeatable"></div><select name="cuztom[' . $field_id_name . '][]" id="' . $field_id_name . '" class="cuztom_input">'; if (is_array($posts)) { foreach ($posts as $post) { echo '<option value="' . $post->ID . '" ' . (!empty($item) ? selected($post->ID, $item, false) : selected($field['default_value'], $post->ID, false)) . '>' . $post->post_title . '</option>'; } } echo '</select>' . (count($value) > 1 ? '<div class="remove_repeatable"></div>' : '') . '</li>'; } } else { echo ($field['repeatable'] ? '<li class="cuztom_field"><div class="handle_repeatable"></div>' : '') . '<select name="cuztom[' . $field_id_name . ']' . ($field['repeatable'] ? '[]' : '') . '" id="' . $field_id_name . '">'; if (is_array($posts)) { foreach ($posts as $post) { echo '<option value="' . $post->ID . '" ' . (!empty($value) ? selected($post->ID, $value, false) : selected($field['default_value'], $post->ID, false)) . '>' . $post->post_title . '</option>'; } } echo '</select>' . ($field['repeatable'] ? '</li>' : ''); } break; // Post checkboxes // Post checkboxes case 'post_checkboxes': $options = array_merge(array('post_type' => 'post'), isset($field['options']) ? $field['options'] : array()); $post_type = $options['post_type']; $posts = get_posts(array('post_type' => $post_type)); echo '<div class="cuztom_post_wrap cuztom_checked_wrap cuztom_padding_wrap">'; if (is_array($posts)) { foreach ($posts as $post) { echo '<input type="checkbox" name="cuztom[' . $field_id_name . '][]" id="' . $field_id_name . '_' . Cuztom::uglify($post->post_title) . '" value="' . $post->ID . '" ' . (!empty($value) ? in_array($post->ID, is_array(maybe_unserialize($value)) ? maybe_unserialize($value) : array()) ? 'checked="checked"' : '' : is_array($field['default_value']) && in_array($post->ID, $field['default_value']) ? 'checked="checked"' : checked($field['default_value'], $post->ID, false)) . ' class="cuztom_input" /> '; echo '<label for="' . $field_id_name . '_' . Cuztom::uglify($post->post_title) . '">' . $post->post_title . '</label>'; echo '<br />'; } } echo '</div>'; break; // Term select // Term select case 'term_select': $options = array_merge(array('taxonomy' => 'category', 'class' => ''), isset($field['options']) ? $field['options'] : array()); $options['name'] = $field_id_name; $options['class'] .= ' cuztom_input'; if ($field['repeatable'] && is_array($value)) { foreach ($value as $item) { $options['selected'] = !empty($item) ? $item : $field['default_value']; $options['name'] = 'cuztom[' . $field_id_name . '][]'; echo '<li class="cuztom_field"><div class="handle_repeatable"></div>'; wp_dropdown_categories($options); echo (count($value) > 1 ? '<div class="remove_repeatable"></div>' : '') . '</li>'; } } else { $options['selected'] = !empty($value) ? $value : $field['default_value']; $options['name'] = 'cuztom[' . $field_id_name . ']' . ($field['repeatable'] ? '[]' : ''); echo $field['repeatable'] ? '<li class="cuztom_field"><div class="handle_repeatable"></div>' : ''; wp_dropdown_categories($options); echo $field['repeatable'] ? '</li>' : ''; } break; // Term checkboxes // Term checkboxes case 'term_checkboxes': $options = array_merge(array('taxonomy' => 'category'), isset($field['options']) ? $field['options'] : array()); $terms = get_terms($options['taxonomy'], array('hide_empty' => false)); echo '<div class="cuztom_taxonomy_wrap cuztom_checked_wrap cuztom_padding_wrap">'; if (is_array($terms)) { foreach ($terms as $term) { echo '<input type="checkbox" name="cuztom[' . $field_id_name . '][]" id="' . $field_id_name . '_' . Cuztom::uglify($term->name) . '" value="' . $term->term_id . '" ' . (!empty($value) ? in_array($term->term_id, is_array(maybe_unserialize($value)) ? maybe_unserialize($value) : array()) ? 'checked="checked"' : '' : is_array($field['default_value']) && in_array($term->term_id, $field['default_value']) ? 'checked="checked"' : checked($field['default_value'], $term->term_id, false)) . ' class="cuztom_input" /> '; echo '<label for="' . $field_id_name . '_' . Cuztom::uglify($term->name) . '">' . $term->name . '</label>'; echo '<br />'; } } echo '</div>'; break; // Hidden field // Hidden field case 'hidden': echo '<input type="hidden" name="cuztom' . $pre . '[' . $field_id_name . ']" id="' . $field_id_name . '" value="' . $field['default_value'] . '" class="cuztom_input" />'; break; // The input type can't be found // The input type can't be found default: _e('Unknown input type', CUZTOM_TEXTDOMAIN); break; } }
/** * Main callback for meta * * @param object $post * @param object $data * @return mixed * * @author Gijs Jorissen * @since 0.2 * */ function callback($post, $data = array()) { // Nonce field for validation wp_nonce_field(plugin_basename(dirname(__FILE__)), 'cuztom_nonce'); // Get all inputs from $data $data = $this->data; if (!empty($data)) { // Hidden field, so cuztom is always set echo '<input type="hidden" name="cuztom[__activate]" />'; echo '<div class="cuztom_helper">'; if ($data instanceof Cuztom_Tabs || $data instanceof Cuztom_Accordion) { $tabs = $data->tabs; // If it's about tabs or accordion echo '<div class="' . ($data instanceof Cuztom_Tabs ? 'cuztom_tabs' : 'cuztom_accordion') . '">'; // Show tabs if ($data instanceof Cuztom_Tabs) { echo '<ul>'; foreach ($tabs as $title => $tab) { $tab_id = Cuztom::uglify($title); echo '<li><a href="#' . $tab_id . '">' . Cuztom::beautify($title) . '</a></li>'; } echo '</ul>'; } /* Loop through $data, tabs in this case */ foreach ($tabs as $title => $tab) { $tab_id = Cuztom::uglify($title); $fields = $tab->fields; // Show header if accordion if ($data instanceof Cuztom_Accordion) { echo '<h3>' . Cuztom::beautify($title) . '</h3>'; } echo '<div id="' . $tab_id . '">'; echo '<table border="0" cellading="0" cellspacing="0" class="cuztom_table cuztom_helper_table">'; foreach ($fields as $field_id_name => $field) { $value = $this->get_meta_type() == 'user' ? get_user_meta($post->ID, $field_id_name, true) : get_post_meta($post->ID, $field_id_name, true); if (!$field instanceof Cuztom_Field_Hidden) { echo '<tr>'; echo '<th class="cuztom_th th">'; echo '<label for="' . $field_id_name . '" class="cuztom_label">' . $field->label . '</label>'; echo '<div class="cuztom_description description">' . $field->description . '</div>'; echo '</th>'; echo '<td class="cuztom_td td">'; if ($field->repeatable && $field->_supports_repeatable()) { echo '<div class="cuztom_padding_wrap">'; echo '<a class="button-secondary cuztom_add cuztom_add_field cuztom_button" href="#">'; echo sprintf('+ %s', __('Add', CUZTOM_TEXTDOMAIN)); echo '</a>'; echo '<ul class="cuztom_repeatable_wrap">'; } echo $field->output($value); if ($field->repeatable && $field->_supports_repeatable()) { echo '</ul></div>'; } echo '</td>'; echo '</tr>'; } else { echo $field->output($value); } } echo '</table>'; echo '</div>'; } echo '</div>'; } elseif ($data instanceof Cuztom_Bundle) { $meta = $this->get_meta_type() == 'user' ? get_user_meta($post->ID, $field_id_name, true) : get_post_meta($post->ID, $field_id_name, true); $meta = $meta[0]; echo '<div class="cuztom_padding_wrap">'; echo '<a class="button-secondary cuztom_add cuztom_add_bundle cuztom_button" href="#">'; echo sprintf('+ %s', __('Add', CUZTOM_TEXTDOMAIN)); echo '</a>'; echo '<ul class="cuztom_bundle_wrap">'; if (!empty($meta) && isset($meta[0])) { $i = 0; foreach ($meta as $bundle) { echo '<li class="cuztom_bundle">'; echo '<div class="handle_bundle"></div>'; echo '<fieldset>'; echo '<table border="0" cellading="0" cellspacing="0" class="cuztom_table cuztom_helper_table">'; $bundle = $data; foreach ($bundle->fields as $field_id_name => $field) { $field->pre = '[' . $this->id . '][' . $i . ']'; $value = isset($meta[$i][$field_id_name]) ? $meta[$i][$field_id_name] : ''; if (!$field instanceof Cuztom_Field_Hidden) { echo '<tr>'; echo '<th class="cuztom_th th">'; echo '<label for="' . $field_id_name . '" class="cuztom_label">' . $field->label . '</label>'; echo '<div class="cuztom_description description">' . $field->description . '</div>'; echo '</th>'; echo '<td class="cuztom_td td">'; if ($field->_supports_bundle()) { echo $field->output($value); } else { _e('<em>This input type doesn\'t support the bundle functionality (yet).</em>'); } echo '</td>'; echo '</tr>'; } else { echo $field->output($value); } } echo '</table>'; echo '</fieldset>'; echo count($meta) > 1 ? '<div class="remove_bundle"></div>' : ''; echo '</li>'; $i++; } } else { echo '<li class="cuztom_bundle">'; echo '<div class="handle_bundle"></div>'; echo '<fieldset>'; echo '<table border="0" cellading="0" cellspacing="0" class="cuztom_table cuztom_helper_table">'; $fields = $data->fields; foreach ($fields as $field_id_name => $field) { $field->pre = '[' . $this->id . '][0]'; $value = ''; if (!$field instanceof Cuztom_Field_Hidden) { echo '<tr>'; echo '<th class="cuztom_th th">'; echo '<label for="' . $field_id_name . '" class="cuztom_label">' . $field->label . '</label>'; echo '<div class="cuztom_description description">' . $field->description . '</div>'; echo '</th>'; echo '<td class="cuztom_td td">'; if ($field->_supports_bundle()) { echo $field->output($value); } else { _e('<em>This input type doesn\'t support the bundle functionality (yet).</em>'); } echo '</td>'; echo '</tr>'; } else { echo $field->output($value); } } echo '</table>'; echo '</fieldset>'; echo '</li>'; } echo '</ul>'; echo '</div>'; } else { echo '<table border="0" cellading="0" cellspacing="0" class="form-table cuztom_table cuztom_helper_table">'; /* Loop through $data */ foreach ($data as $field_id_name => $field) { $meta = $this->get_meta_type() == 'user' ? get_user_meta($post->ID, $field_id_name, true) : get_post_meta($post->ID, $field_id_name, true); if (!$field instanceof Cuztom_Field_Hidden) { echo '<tr>'; echo '<th class="cuztom_th th">'; echo '<label for="' . $field_id_name . '" class="cuztom_label">' . $field->label . '</label>'; echo '<div class="cuztom_description description">' . $field->description . '</div>'; echo '</th>'; echo '<td class="cuztom_td td">'; if ($field->repeatable && $field->_supports_repeatable()) { echo '<div class="cuztom_padding_wrap">'; echo '<a class="button-secondary cuztom_add cuztom_add_field cuztom_button" href="#">'; echo sprintf('+ %s', __('Add', CUZTOM_TEXTDOMAIN)); echo '</a>'; echo '<ul class="cuztom_repeatable_wrap">'; } echo $field->output($meta); if ($field->repeatable && $field->_supports_repeatable()) { echo '</ul></div>'; } echo '</td>'; echo '</tr>'; } else { echo $field->output($meta); } } echo '</table>'; } echo '</div>'; } }
function __construct($title) { $this->id = Cuztom::uglify($title); $this->title = Cuztom::beautify($title); }
/** * Main callback function of add_meta_box * * @param object $post * @param object $data * @return mixed * * @author Gijs Jorissen * @since 0.2 * */ function callback($post, $data) { // Nonce field for validation wp_nonce_field(plugin_basename(__FILE__), 'cuztom_nonce'); // Get all inputs from $data $meta_data = $this->meta_data; // Check the array and loop through it if (!empty($meta_data)) { // Hidden field, so cuztom is always set echo '<input type="hidden" name="cuztom[__activate]" />'; if (isset($meta_data[0]) && !is_array($meta_data[0]) && ($meta_data[0] == 'tabs' || $meta_data[0] == 'accordion')) { $tabs = array_slice($meta_data, 1); // If it's about tabs or accordion echo '<div class="cuztom_helper">'; echo '<div class="' . ($meta_data[0] == 'tabs' ? 'cuztom_tabs' : 'cuztom_accordion') . '">'; // Show tabs if ($meta_data[0] == 'tabs') { echo '<ul>'; foreach ($tabs as $tab => $fields) { $tab_id = Cuztom::uglify($tab); echo '<li><a href="#' . $tab_id . '">' . Cuztom::beautify($tab) . '</a></li>'; } echo '</ul>'; } /* Loop through $meta_data, tabs in this case */ foreach ($tabs as $tab => $fields) { $tab_id = Cuztom::uglify($tab); // Show header if accordion if ($meta_data[0] == 'accordion') { echo '<h3>' . Cuztom::beautify($title) . '</h3>'; } echo '<div id="' . $tab_id . '">'; echo '<table border="0" cellading="0" cellspacing="0" class="cuztom_table cuztom_helper_table">'; foreach ($fields as $field_id_name => $field) { $meta = get_post_meta($post->ID, $field_id_name, true); if ($field['type'] != 'hidden') { echo '<tr>'; echo '<th class="cuztom_th th">'; echo '<label for="' . $field_id_name . '" class="cuztom_label">' . $field['label'] . '</label>'; echo '<div class="cuztom_description description">' . $field['description'] . '</div>'; echo '</th>'; echo '<td class="cuztom_td td">'; if ($field['repeatable'] && Cuztom_Field::_supports_repeatable($field)) { echo '<div class="cuztom_padding_wrap">'; echo '<a class="button-secondary cuztom_add cuztom_button" href="#">'; echo '+ ' . __('Add', CUZTOM_TEXTDOMAIN) . '</a>'; echo '<ul class="cuztom_repeatable_wrap">'; } cuztom_field($field_id_name, $field, $meta); if ($field['repeatable'] && Cuztom_Field::_supports_repeatable($field)) { echo '</ul></div>'; } echo '</td>'; echo '</tr>'; } else { cuztom_field($field_id_name, $field, $meta); } } echo '</table>'; echo '</div>'; } echo '</div>'; echo '</div>'; } else { echo '<div class="cuztom_helper">'; echo '<table border="0" cellading="0" cellspacing="0" class="cuztom_table cuztom_helper_table">'; /* Loop through $meta_data */ foreach ($meta_data as $field_id_name => $field) { $meta = get_post_meta($post->ID, $field_id_name, true) ? get_post_meta($post->ID, $field_id_name, true) : false; if ($field['type'] != 'hidden') { echo '<tr>'; echo '<th class="cuztom_th th">'; echo '<label for="' . $field_id_name . '" class="cuztom_label">' . $field['label'] . '</label>'; echo '<div class="cuztom_description description">' . $field['description'] . '</div>'; echo '</th>'; echo '<td class="cuztom_td td">'; if ($field['repeatable'] && Cuztom_Field::_supports_repeatable($field)) { echo '<div class="cuztom_padding_wrap">'; echo '<a class="button-secondary cuztom_add cuztom_button" href="#">'; echo '+ ' . __('Add', CUZTOM_TEXTDOMAIN) . '</a>'; echo '<ul class="cuztom_repeatable_wrap">'; } cuztom_field($field_id_name, $field, $meta); if ($field['repeatable'] && Cuztom_Field::_supports_repeatable($field)) { echo '</ul></div>'; } echo '</td>'; echo '</tr>'; } else { cuztom_field($field_id_name, $field, $meta); } } echo '</table>'; echo '</div>'; } } }