/** * Register custom sidebars. * * @since 1.0.0 */ function themeblvd_register_custom_sidebars() { // Get custom sidebars $custom_sidebars = get_posts('post_type=tb_sidebar&numberposts=-1&orderby=title&order=ASC'); // Register custom sidebars foreach ($custom_sidebars as $sidebar) { // Setup arguments for register_sidebar() $args = array('name' => __('Custom', 'themeblvd_sidebars') . ': ' . $sidebar->post_title, 'id' => $sidebar->post_name, 'before_widget' => '<aside id="%1$s" class="widget %2$s"><div class="widget-inner">', 'after_widget' => '</div></aside>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>'); $location = get_post_meta($sidebar->ID, 'location', true); if ($location && $location != 'floating') { $args['description'] = sprintf(__('This is a custom widget area to replace the %s on its assigned pages.', 'themeblvd_sidebars'), themeblvd_get_sidebar_location_name($location)); } else { $args['description'] = __('This is a custom floating widget area.', 'themeblvd_sidebars'); } // Extend $args = apply_filters('themeblvd_custom_sidebar_args', $args, $sidebar, $location); // Register the sidebar register_sidebar($args); } }
/** * Generates a table for a custom post type. * * @since 2.0.0 * * @param $post_type string post type id * @param $columns array columns for table * @return $output string HTML output for table */ function themeblvd_post_table($post_type, $columns) { // Grab some details for post type $post_type_object = get_post_type_object($post_type); $name = $post_type_object->labels->name; $singular_name = $post_type_object->labels->singular_name; // Get posts $posts = get_posts(array('post_type' => $post_type, 'numberposts' => -1, 'orderby' => 'title', 'order' => 'ASC')); // Get conflicts if this is a sidebar table if ($post_type == 'tb_sidebar') { $conflicts = themeblvd_get_assignment_conflicts($posts); } // Setup header/footer $header = '<tr>'; $header .= '<th scope="col" id="cb" class="manage-column column-cb check-column"><input type="checkbox"></th>'; foreach ($columns as $column) { $header .= '<th class="head-' . $column['type'] . '">' . $column['name'] . '</th>'; } $header .= '</tr>'; // Start main output $output = '<table class="widefat">'; $output .= '<div class="tablenav top">'; $output .= '<div class="alignleft actions">'; $output .= '<select name="action">'; $output .= '<option value="-1" selected="selected">' . __('Bulk Actions', 'themeblvd') . '</option>'; $output .= '<option value="trash">' . __('Delete', 'themeblvd') . ' ' . esc_attr($name) . '</option>'; $output .= '</select>'; $output .= '<input type="submit" id="doaction" class="button-secondary action" value="' . __('Apply', 'themeblvd') . '">'; $output .= '</div>'; $output .= '<div class="alignright tablenav-pages">'; $output .= '<span class="displaying-num">' . sprintf(_n('1 ' . $singular_name, '%s ' . $name, count($posts)), number_format_i18n(count($posts))) . '</span>'; $output .= '</div>'; $output .= '<div class="clear"></div>'; $output .= '</div>'; // Table header $output .= '<thead>'; $output .= $header; $output .= '</thead>'; // Table footer $output .= '<tfoot>'; $output .= $header; $output .= '</tfoot>'; // Table body $output .= '<tbody>'; if (!empty($posts)) { foreach ($posts as $post) { $output .= '<tr id="row-' . $post->ID . '">'; $output .= '<th scope="row" class="check-column"><input type="checkbox" name="posts[]" value="' . $post->ID . '"></th>'; foreach ($columns as $column) { switch ($column['type']) { case 'title': $output .= '<td class="post-title page-title column-title">'; $output .= '<strong><a href="#' . esc_attr($post->ID) . '" class="title-link edit-' . $post_type . '" title="' . __('Edit', 'themeblvd') . '">' . stripslashes(esc_html($post->post_title)) . '</strong></a>'; $output .= '<div class="row-actions">'; $output .= '<span class="edit">'; $output .= '<a href="#' . esc_attr($post->ID) . '" class="edit-post edit-' . $post_type . '" title="' . __('Edit', 'themeblvd') . '">' . __('Edit', 'themeblvd') . '</a> | '; $output .= '</span>'; $output .= '<span class="trash">'; $output .= '<a title="' . __('Delete', 'themeblvd') . '" href="#' . esc_attr($post->ID) . '">' . __('Delete', 'themeblvd') . '</a>'; $output .= '</span>'; $output .= '</div>'; break; case 'id': $output .= '<td class="post-id">'; $output .= esc_html($post->ID); break; case 'slug': $output .= '<td class="post-slug">'; $output .= esc_html($post->post_name); break; case 'meta': $output .= '<td class="post-meta-' . $column['config'] . '">'; $meta = get_post_meta($post->ID, $column['config'], true); if (isset($column['inner'])) { if (isset($meta[$column['inner']])) { $output .= esc_html($meta[$column['inner']]); } } else { $output .= esc_html($meta); } break; case 'shortcode': $output .= '<td class="post-shortcode-' . $column['config'] . '">'; $output .= '[' . $column['config'] . ' id="' . $post->post_name . '"]'; break; case 'assignments': $output .= '<td class="post-assignments">'; $location = get_post_meta($post->ID, 'location', true); if ($location && $location != 'floating') { $assignments = get_post_meta($post->ID, 'assignments', true); if (is_array($assignments) && !empty($assignments)) { $output .= '<ul>'; foreach ($assignments as $key => $assignment) { $class = 'no-conflict'; if (in_array($key, $conflicts[$location])) { $class = 'conflict'; } if ($assignment['type'] == 'top') { $output .= '<li class="' . $class . '">' . esc_html($assignment['name']) . '</li>'; } elseif ($assignment['type'] == 'custom') { $output .= '<li class="' . $class . '">' . ucfirst(esc_html($assignment['type'])) . ': <code>' . esc_html($assignment['name']) . '</code></li>'; } else { $output .= '<li class="' . $class . '">' . ucfirst(esc_html($assignment['type'])) . ': ' . esc_html($assignment['name']) . '</li>'; } } $output .= '</ul>'; } else { $output .= '<span class="inactive">' . __('No Assignments', 'themeblvd') . '</span>'; } } else { $output .= '<span class="inactive">[floating]</span>'; } break; case 'sidebar_location': $output .= '<td class="sidebar-location">'; $output .= themeblvd_get_sidebar_location_name(esc_html(get_post_meta($post->ID, 'location', true))); break; } $output .= '</td>'; } $output .= '</tr>'; } } else { $num = count($columns) + 1; // number of columns + the checkbox column $output .= '<tr><td colspan="' . $num . '">' . __('No items have been created yet. Click the Add tab above to get started.', 'themeblvd') . '</td></tr>'; } $output .= '</tbody>'; $output .= '</table>'; return $output; }