/** * Adds custom rewrite rules for the plugin. * * @since 1.0.0 * @access public * @return void */ function thds_rewrite_rules() { $theme_type = thds_get_theme_post_type(); $author_slug = thds_get_author_rewrite_slug(); // Where to place the rewrite rules. If no rewrite base, put them at the bottom. $after = thds_get_author_rewrite_base() ? 'top' : 'bottom'; add_rewrite_rule($author_slug . '/([^/]+)/page/?([0-9]{1,})/?$', 'index.php?post_type=' . $theme_type . '&author_name=$matches[1]&paged=$matches[2]', $after); add_rewrite_rule($author_slug . '/([^/]+)/?$', 'index.php?post_type=' . $theme_type . '&author_name=$matches[1]', $after); }
/** * Sets up custom admin menus. * * @since 1.0.0 * @access public * @return void */ public function admin_menu() { // Create the settings page. $this->settings_page = add_submenu_page('edit.php?post_type=' . thds_get_theme_post_type(), esc_html__('Theme Designer Settings', 'theme-designer'), esc_html__('Settings', 'theme-designer'), apply_filters('thds_settings_capability', 'manage_options'), 'thds-settings', array($this, 'settings_page')); if ($this->settings_page) { // Register settings. add_action('admin_init', array($this, 'register_settings')); // Add help tabs. /// add_action( "load-{$this->settings_page}", array( $this, 'add_help_tabs' ) ); } }
/** * Returns the author archive URL. * * @since 1.0.0 * @access public * @param int $user_id * @global object $wp_rewrite * @global object $authordata * @return string */ function thds_get_author_url($user_id = 0) { global $wp_rewrite, $authordata; $url = ''; // If no user ID, see if there's some author data we can get it from. if (!$user_id && is_object($authordata)) { $user_id = $authordata->ID; } // If we have a user ID, build the URL. if ($user_id) { // Get the author's nicename. $nicename = get_the_author_meta('user_nicename', $user_id); // Pretty permalinks. if ($wp_rewrite->using_permalinks()) { $url = home_url(user_trailingslashit(trailingslashit(thds_get_author_rewrite_slug()) . $nicename)); } else { $url = add_query_arg(array('post_type' => thds_get_theme_post_type(), 'author_name' => $nicename), home_url('/')); } } return apply_filters('thds_get_author_url', $url, $user_id); }
/** * Adds custom bulk post updated messages on the manage themes screen. * * @since 1.0.0 * @access public * @param array $messages * @param array $counts * @return array */ function thds_bulk_post_updated_messages($messages, $counts) { $type = thds_get_theme_post_type(); $messages[$type]['updated'] = _n('%s theme updated.', '%s themes updated.', $counts['updated'], 'theme-designer'); $messages[$type]['locked'] = _n('%s theme not updated, somebody is editing it.', '%s themes not updated, somebody is editing them.', $counts['locked'], 'theme-designer'); $messages[$type]['deleted'] = _n('%s theme permanently deleted.', '%s themes permanently deleted.', $counts['deleted'], 'theme-designer'); $messages[$type]['trashed'] = _n('%s theme moved to the Trash.', '%s themes moved to the trash.', $counts['trashed'], 'theme-designer'); $messages[$type]['untrashed'] = _n('%s theme restored from the Trash.', '%s themes restored from the trash.', $counts['untrashed'], 'theme-designer'); return $messages; }
/** * Adds sticky posts to the front of the line with any given set of posts and stickies. * * @since 1.0.0 * @access public * @param array $posts Array of post objects. * @param array $sticky_posts Array of post IDs. * @return array */ function thds_add_stickies($posts, $sticky_posts) { // Only do this if on the first page and we indeed have stickies. if (!empty($sticky_posts)) { $num_posts = count($posts); $sticky_offset = 0; // Loop over posts and relocate stickies to the front. for ($i = 0; $i < $num_posts; $i++) { if (in_array($posts[$i]->ID, $sticky_posts)) { $sticky_post = $posts[$i]; // Remove sticky from current position. array_splice($posts, $i, 1); // Move to front, after other stickies. array_splice($posts, $sticky_offset, 0, array($sticky_post)); // Increment the sticky offset. The next sticky will be placed at this offset. $sticky_offset++; // Remove post from sticky posts array. $offset = array_search($sticky_post->ID, $sticky_posts); unset($sticky_posts[$offset]); } } // Fetch sticky posts that weren't in the query results. if (!empty($sticky_posts)) { $args = array('post__in' => $sticky_posts, 'post_type' => thds_get_theme_post_type(), 'post_status' => 'publish', 'nopaging' => true); $stickies = get_posts($args); foreach ($stickies as $sticky_post) { array_splice($posts, $sticky_offset, 0, array($sticky_post)); $sticky_offset++; } } } return $posts; }
/** * Outputs the content template. * * @since 1.0.0 * @access public * @return void */ public function content_template($post_id) { $post = get_post($post_id); $themes = get_posts(array('post_type' => thds_get_theme_post_type(), 'post_status' => 'any', 'post__not_in' => array($post_id), 'posts_per_page' => -1, 'post_parent' => 0, 'orderby' => 'title', 'order' => 'ASC', 'fields' => array('ID', 'post_title'))); ?> <label> <?php if ($this->label) { ?> <span class="thds-fields-label"><?php echo esc_html($this->label); ?> </span> <br /> <?php } ?> <select name="parent_id" id="parent_id"> <option value="0" <?php selected(0, $post->post_parent); ?> ></option> <?php if ($themes) { ?> <?php foreach ($themes as $theme) { ?> <option value="<?php echo esc_attr($theme->ID); ?> " <?php selected($theme->ID, $post->post_parent); ?> ><?php echo esc_html($theme->post_title); ?> </option> <?php } ?> <?php } ?> </select> <?php if ($this->description) { ?> <br /> <span class="thds-fields-description description"><?php echo $this->description; ?> </span> <?php } ?> </label> <?php }
/** * Returns the theme archive URL. * * @since 1.0.0 * @access public * @return string */ function thds_get_theme_archive_url() { return apply_filters('thds_get_theme_archive_url', get_post_type_archive_link(thds_get_theme_post_type())); }
/** * Filter on the post author drop-down (used in the "Author" meta box) to only show users * of roles that have the correct capability for editing portfolio themes. * * @since 1.0.0 * @access public * @param array $args * @param array $r * @global object $wp_roles * @global object $post * @return array */ function dropdown_users_args($args, $r) { global $wp_roles, $post; // WP version 4.4.0 check. Bail if we can't use the `role__in` argument. if (!method_exists('WP_User_Query', 'fill_query_vars')) { return $args; } // Check that this is the correct drop-down. if ('post_author_override' === $r['name'] && thds_get_theme_post_type() === $post->post_type) { $roles = array(); // Loop through the available roles. foreach ($wp_roles->roles as $name => $role) { // Get the edit posts cap. $cap = get_post_type_object(thds_get_theme_post_type())->cap->edit_posts; // If the role is granted the edit posts cap, add it. if (isset($role['capabilities'][$cap]) && true === $role['capabilities'][$cap]) { $roles[] = $name; } } // If we have roles, change the args to only get users of those roles. if ($roles) { $args['who'] = ''; $args['role__in'] = $roles; } } return $args; }
/** * Register taxonomies for the plugin. * * @since 0.1.0 * @access public * @return void. */ function thds_register_taxonomies() { // Set up the arguments for the subject taxonomy. $subject_args = array('public' => true, 'show_ui' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, 'show_admin_column' => true, 'hierarchical' => true, 'query_var' => thds_get_subject_taxonomy(), 'capabilities' => thds_get_subject_capabilities(), 'labels' => thds_get_subject_labels(), 'rewrite' => array('slug' => thds_get_subject_rewrite_slug(), 'with_front' => false, 'hierarchical' => false, 'ep_mask' => EP_NONE)); // Set up the arguments for the feature taxonomy. $feature_args = array('public' => true, 'show_ui' => true, 'show_in_nav_menus' => true, 'show_tagcloud' => true, 'show_admin_column' => false, 'hierarchical' => false, 'query_var' => thds_get_feature_taxonomy(), 'capabilities' => thds_get_feature_capabilities(), 'labels' => thds_get_feature_labels(), 'rewrite' => array('slug' => thds_get_feature_rewrite_slug(), 'with_front' => false, 'hierarchical' => false, 'ep_mask' => EP_NONE)); // Register the taxonomies. register_taxonomy(thds_get_subject_taxonomy(), thds_get_theme_post_type(), apply_filters('thds_subject_taxonomy_args', $subject_args)); register_taxonomy(thds_get_feature_taxonomy(), thds_get_theme_post_type(), apply_filters('thds_feature_taxonomy_args', $feature_args)); }
/** * Custom row actions below the post title. * * @since 1.0.0 * @access public * @param array $actions * @param object $post * @return array */ function row_actions($actions, $post) { $post_type_object = get_post_type_object(thds_get_theme_post_type()); $theme_id = thds_get_theme_id($post->ID); if ('trash' === get_post_status($theme_id) || !current_user_can($post_type_object->cap->publish_posts)) { return $actions; } $current_url = remove_query_arg(array('theme_id', 'thds_theme_notice')); // Build text. $text = thds_is_theme_sticky($theme_id) ? esc_html__('Unstick', 'theme-designer') : esc_html__('Stick', 'theme-designer'); // Build toggle URL. $url = add_query_arg(array('theme_id' => $theme_id, 'action' => 'thds_toggle_sticky'), $current_url); $url = wp_nonce_url($url, "thds_toggle_sticky_{$theme_id}"); // Add sticky action. $actions['sticky'] = sprintf('<a href="%s" class="%s">%s</a>', esc_url($url), 'sticky', esc_html($text)); // Move view action to the end. if (isset($actions['view'])) { $view_action = $actions['view']; unset($actions['view']); $actions['view'] = $view_action; } return $actions; }
/** * Filter on 'post_type_archive_title' to allow for the use of the 'archive_title' label that isn't supported * by WordPress. That's okay since we can roll our own labels. * * @since 0.1.0 * @access public * @param string $title * @param string $post_type * @return string */ function thds_post_type_archive_title($title, $post_type) { $theme_type = thds_get_theme_post_type(); return $theme_type === $post_type ? get_post_type_object($theme_type)->labels->archive_title : $title; }