예제 #1
0
/**
 * Displays a taxonomy dropdown box metabox
 *
 * @param \WP_Post $post The currently edited post
 * @param array $metabox Contains args from the add_meta_box func. Important one: pass in a Taxonomy object.
 */
function create_taxonomy_dropdown_metabox($post, $metabox)
{
    $taxonomy = $metabox['args']['taxonomy'];
    //bail if invalid taxonomy or not an object
    if (!is_object($taxonomy) || is_object($taxonomy) && !get_taxonomy($taxonomy->name)) {
        return;
    }
    // uses same noncename as default box so no save_post hook needed
    wp_nonce_field('taxonomy_' . $taxonomy->name, 'taxonomy_noncename');
    // get terms associated with this post
    $names = get_the_terms(get_the_ID(), $taxonomy->name);
    // get all terms in this taxonomy
    $terms = (array) get_terms($taxonomy->name, 'hide_empty=0');
    if (!$terms) {
        echo '<p>' . sprintf(esc_html_x('No %s created.', 'When no terms are present, i.e. "No publications created."', 'eight-day-week'), esc_html($taxonomy->labels->name)) . '</p>';
        return;
    }
    // filter the ids out of the terms
    $existing = !is_wp_error($names) && !empty($names) ? (array) wp_list_pluck($names, 'term_id') : [];
    // Check if taxonomy is hierarchical
    // Terms are saved differently between types
    $h = $taxonomy->hierarchical;
    // default value
    $default_val = $h ? 0 : '';
    // input name
    $name = $h ? 'tax_input[' . $taxonomy->name . '][]' : 'tax_input[' . $taxonomy->name . ']';
    $default_text = sprintf(_x('No %s', 'Provides a select option for choosing "no" term.', 'eight-day-week'), esc_html($taxonomy->labels->singular_name));
    $select = '';
    $selected_term = false;
    $select .= '<select name="' . esc_attr($name) . '" id="' . esc_attr($taxonomy->name) . '_dropdownlist">';
    if (count($terms) > 1) {
        //default option
        $select .= '<option value="' . esc_attr($default_val) . '"';
        $select .= esc_attr(selected(empty($existing), true, false));
        $select .= '>' . esc_html($default_text) . '</option>';
    }
    // loop terms and check if they're associated with this post
    if ($terms) {
        foreach ($terms as $term) {
            $val = $h ? $term->term_id : $term->slug;
            $select .= '<option value="' . absint($val) . '"';
            // if so, they get "checked"
            $selected = !empty($existing) && in_array((int) $term->term_id, $existing) || count($terms) <= 1;
            $select .= selected($selected, true, false);
            $select .= '> ' . esc_html($term->name) . '</option>';
            //this is used for print prod users
            if ($selected) {
                $selected_term = $term->name;
            }
        }
    }
    $select .= '</select>';
    if (User\current_user_can_edit_print_issue()) {
        echo wp_kses($select, ['option' => ['value' => [], 'selected' => []], 'select' => ['name' => [], 'id' => []]]);
    } else {
        echo '<p> ' . esc_html($selected_term ? $selected_term : $default_text) . '</p>';
    }
}
예제 #2
0
/**
 * Modifies the <title> element to reflect RO view on PI editor screen
 *
 * @param $title string Incoming title
 *
 * @return string Modified title
 */
function filter_admin_title_for_rov($title)
{
    if (EDW_PRINT_ISSUE_CPT === get_post_type()) {
        if (is_read_only_view() || !User\current_user_can_edit_print_issue()) {
            $title = esc_html__('Print Issue (Read Only)', 'eight-day-week');
        }
    }
    return $title;
}
예제 #3
0
/**
 * Outputs the article status buttons/select box
 * Only does so for an print-issue-edit-capable user
 */
function output_bulk_article_status_editor()
{
    if (!User\current_user_can_edit_print_issue()) {
        return;
    }
    $statuses = get_indexed_article_statuses();
    ?>
	<div class="alignleft actions bulkactions">
		<h3><label for="bulk-action-selector-top"><?php 
    esc_html_e('Article Status', 'eight-day-week');
    ?>
</label></h3>
		<select id="bulk-action-selector-top">
			<?php 
    if ($statuses) {
        ?>
				<?php 
        foreach ($statuses as $id => $status) {
            ?>
					<option value="<?php 
            echo absint($id);
            ?>
"><?php 
            echo esc_html($status);
            ?>
</option>
				<?php 
        }
        ?>
			<?php 
    }
    ?>
		</select>
		<button id="bulk-edit-article-status-submit" class="button button-secondary"><?php 
    esc_html_e('Apply to checked', 'eight-day-week');
    ?>
</button>
		<button id="bulk-edit-article-status-apply-all" class="button button-secondary"><?php 
    esc_html_e('Apply to all', 'eight-day-week');
    ?>
</button>
	</div>
	<?php 
}
예제 #4
0
/**
 * Outputs a Save button
 */
function section_save_button()
{
    if (Print_Issue\is_read_only_view() || !User\current_user_can_edit_print_issue()) {
        return;
    }
    echo '<button class="button button-primary">' . esc_html('Save', 'eight-day-week') . '</button>';
}
예제 #5
0
 /**
  * Gets the post title + actions for the post
  *
  * @param \WP_Post $item The current post
  *
  * @return string The posts's title
  */
 function column_title($item)
 {
     if (current_user_can('edit_post', $item->ID)) {
         $title = '<a class="pi-article-title" href="' . esc_url(get_edit_post_link($item->ID)) . '">' . esc_html(get_the_title($item->ID)) . '</a>';
     } else {
         $title = esc_html(get_the_title($item->ID));
     }
     $title .= '<a class="pi-article-view" target="_blank" href="' . esc_url(get_permalink($item->ID)) . '">' . __('View', 'eight-day-week') . '</a>';
     //don't give remove link to print prod users
     if (User\current_user_can_edit_print_issue()) {
         $title .= '<a class="pi-article-remove" href="javascript:;" data-article-id="' . absint($item->ID) . '">Remove</a>';
     }
     return $title;
 }