Пример #1
0
function wpmtst_single_form_field($field)
{
    $form_values = WPMST()->get_form_values();
    echo '<p class="form-field">';
    echo '<label for="wpmtst_' . $field['name'] . '">' . apply_filters('wpmtst_l10n', $field['label'], 'strong-testimonials-form-fields', $field['name'] . ' : label') . '</label>';
    wpmtst_field_required_symbol($field);
    wpmtst_field_before($field);
    switch ($field['input_type']) {
        case 'categories':
            $value = isset($form_values[$field['name']]) ? $form_values[$field['name']] : '';
            $category_list = wpmtst_get_category_list();
            echo '<select id="wpmtst_' . $field['name'] . '"' . ' name="' . $field['name'] . '"' . ' class="' . wpmtst_field_classes($field['input_type'], $field['name']) . '"' . wpmtst_field_required_tag($field) . ' autocomplete="off">';
            echo '<option value="">&mdash;</option>';
            foreach ($category_list as $category) {
                echo '<option value="' . $category->term_id . '" ' . selected($category->term_id, $value) . '>';
                echo $category->name;
                echo '</option>';
            }
            echo '</select>';
            break;
        case 'textarea':
            $value = isset($form_values[$field['name']]) && $form_values[$field['name']] ? $form_values[$field['name']] : '';
            // textarea tags must be on same line for placeholder to work
            echo '<textarea id="wpmtst_' . $field['name'] . '"' . ' class="' . wpmtst_field_classes($field['input_type'], $field['name']) . '"' . ' name="' . $field['name'] . '"' . wpmtst_field_required_tag($field) . wpmtst_field_placeholder($field) . '>' . $value . '</textarea>';
            break;
        case 'file':
            echo '<input id="wpmtst_' . $field['name'] . '" type="file" name="' . $field['name'] . '">';
            break;
        default:
            // test, email, url
            /**
             * Switching out url type until more themes adopt it.
             * @since 1.11.0
             */
            $input_type = $field['input_type'] = 'url' ? 'text' : $field['input_type'];
            $value = isset($form_values[$field['name']]) ? $form_values[$field['name']] : '';
            echo '<input id="wpmtst_' . $field['name'] . '"' . ' type="' . $input_type . '"' . ' class="' . wpmtst_field_classes($field['input_type'], $field['name']) . '"' . ' name="' . $field['name'] . '"' . ' value="' . $value . '"' . wpmtst_field_placeholder($field) . wpmtst_field_required_tag($field) . '>';
    }
    wpmtst_field_error($field);
    wpmtst_field_after($field);
    echo '</p>' . "\n";
}
Пример #2
0
/**
 * An individual view settings page.
 *
 * @since 1.21.0
 *
 * @param string $action
 * @param null   $view_id
 */
function wpmtst_view_settings($action = '', $view_id = null)
{
    if (('edit' == $action || 'duplicate' == $action) && !$view_id) {
        return;
    }
    global $view, $strong_templates;
    add_thickbox();
    $screen = get_current_screen();
    $url = $screen->parent_file;
    $fields = wpmtst_get_custom_fields();
    $all_fields = wpmtst_get_all_fields();
    $order_list = wpmtst_get_order_list();
    $posts_list = get_posts(array('orderby' => 'post_date', 'order' => 'ASC', 'post_type' => 'wpm-testimonial', 'post_status' => 'publish', 'posts_per_page' => -1, 'suppress_filters' => true));
    $category_list = wpmtst_get_category_list();
    /**
     * Show category filter if necessary.
     *
     * @since 2.2.0
     */
    if (count($category_list) > 5) {
        wp_enqueue_script('wpmtst-view-category-filter-script');
    }
    $pages_list = get_pages(array('sort_order' => 'ASC', 'sort_column' => 'menu_order', 'post_type' => 'page', 'post_status' => 'publish'));
    $view_options = get_option('wpmtst_view_options');
    $default_view = get_option('wpmtst_view_default');
    if ('edit' == $action) {
        $view_array = wpmtst_get_view($view_id);
        $view = unserialize($view_array['value']);
        $view_name = $view_array['name'];
    } elseif ('duplicate' == $action) {
        $view_array = wpmtst_get_view($view_id);
        $view = unserialize($view_array['value']);
        $view_id = 0;
        $view_name = $view_array['name'] . ' - COPY';
    } else {
        $view_id = 1;
        $view = $default_view;
        $view_name = 'new';
    }
    // Deselect title & thumbnail if not in field group
    $has_title_field = false;
    $has_thumbnail_field = false;
    foreach ($all_fields as $key => $field) {
        if ('post_title' == $field['name']) {
            $has_title_field = true;
        }
        if ('featured_image' == $field['name']) {
            $has_thumbnail_field = true;
        }
    }
    if (!$has_title_field) {
        $view['title'] = false;
    }
    if (!$has_thumbnail_field) {
        $view['thumbnail'] = false;
    }
    // Select default template if necessary
    if (!$view['template']) {
        if ('form' == $view['mode']) {
            $view['template'] = 'default:form';
        } else {
            $view['template'] = 'default:content';
        }
    }
    $view['nav'] = explode(',', str_replace(' ', '', $view['nav']));
    //$view_cats_array = explode( ',', $view['category'] );
    $view_cats_array = apply_filters('wpmtst_l10n_cats', explode(',', $view['category']));
    // Assemble list of templates
    $templates = $strong_templates->get_templates(array('content', 'widget'));
    $form_templates = $strong_templates->get_templates('form');
    $group = strtok($view['template'], ':');
    $type = strtok(':');
    if ('form' == $type) {
        $template_found = in_array($view['template'], array_keys($form_templates));
    } else {
        $template_found = in_array($view['template'], array_keys($templates));
    }
    // Get list of image sizes
    $image_sizes = wpmtst_get_image_sizes();
    ?>
	<h2>
		<?php 
    'edit' == $action ? _e('Edit View', 'strong-testimonials') : _e('Add View', 'strong-testimonials');
    ?>
		<a href="<?php 
    echo $url;
    ?>
&page=testimonial-views&action=add" class="add-new-h2">Add New</a>
	</h2>

	<p><a href="<?php 
    echo admin_url('edit.php?post_type=wpm-testimonial&page=testimonial-views');
    ?>
">Return to list</a></p>

	<form id="wpmtst-views-form" method="post" action="<?php 
    echo get_admin_url() . 'admin-post.php';
    ?>
" autocomplete="off">

		<?php 
    wp_nonce_field('view_form_submit', 'view_form_nonce', true, true);
    ?>

		<input type="hidden" name="action" value="view_<?php 
    echo $action;
    ?>
_form">
		<input type="hidden" name="view[id]" value="<?php 
    echo $view_id;
    ?>
">
		<input type="hidden" name="view_original_mode" value="<?php 
    echo $view['mode'];
    ?>
">
		<input type="hidden" name="view[data][_form_id]" value="<?php 
    echo $view['form_id'];
    ?>
">

		<div class="view-info">
			<div class="form-view-name"><span class="title">Name:</span><input type="text" id="view-name" class="view-name" name="view[name]" value="<?php 
    echo $view_name;
    ?>
" tabindex="1"></div>
		</div>
			<div class="view-info">
				<div class="form-view-shortcode">
					<span class="title">Shortcode:</span>
					<?php 
    if ('edit' == $action) {
        ?>
					<span class="saved">[testimonial_view id=<?php 
        echo $view_id;
        ?>
]</span>
					<?php 
    } else {
        ?>
					<span class="unsaved"><?php 
        _ex('will be available after you save this', 'The shortcode for a new View.', 'strong-testimonials');
        ?>
</span>
					<?php 
    }
    ?>
				</div>
			</div>

		<?php 
    include 'views/mode.php';
    // TODO Generify both hook and include
    do_action('wpmtst_view_editor_before_group_select');
    include 'views/group-select.php';
    do_action('wpmtst_view_editor_before_group_fields');
    include 'views/group-fields.php';
    do_action('wpmtst_view_editor_before_group_form');
    include 'views/group-form.php';
    do_action('wpmtst_view_editor_before_group_extra');
    include 'views/group-extra.php';
    do_action('wpmtst_view_editor_before_group_style');
    include 'views/group-style.php';
    do_action('wpmtst_view_editor_before_group_general');
    include 'views/group-general.php';
    do_action('wpmtst_view_editor_after_groups');
    ?>

		<p class="wpmtst-submit">
			<?php 
    submit_button('', 'primary', 'submit', false);
    ?>
			<?php 
    submit_button(__('Undo Changes', 'strong-testimonials'), 'secondary', 'reset', false);
    ?>
			<?php 
    submit_button(__('Restore Defaults', 'strong-testimonials'), 'secondary', 'restore-defaults', false);
    ?>
		</p>

	</form>
	<?php 
}
Пример #3
0
/**
 * Add custom columns to the admin list.
 *
 * @param $columns
 * @since 1.4.0
 * @since 2.5.1  Added comments column.
 * @return array
 */
function wpmtst_edit_columns($columns)
{
    $fields = wpmtst_get_all_fields();
    $comments = isset($columns['comments']) ? $columns['comments'] : '';
    /*
    	INCOMING COLUMNS = Array (
    		[cb] => <input type="checkbox" />
    		[title] => Title
    		[comments] => <span class="vers comment-grey-bubble" title="Comments"><span class="screen-reader-text">Comments</span></span>
    		[date] => Date
    		[search_exclude] => Search Exclude   // other plugin
    		[thumbnail] => Thumbnail
    	)
    */
    // 1. remove [thumbnail] (may be re-added in custom field loop) and [date]
    unset($columns['thumbnail'], $columns['date']);
    if ($comments) {
        unset($columns['comments']);
    }
    // 2. insert [order] after [cb]
    if (!wpmtst_is_column_sorted() && !wpmtst_is_viewing_trash() && class_exists('Strong_Testimonials_Order')) {
        $columns = array_merge(array_slice($columns, 0, 1), array('handle' => 'Order'), array_slice($columns, 1, null));
    }
    // 3. insert [excerpt] after [title]
    $key = 'title';
    $offset = array_search($key, array_keys($columns)) + 1;
    $fields_to_add = array('post_excerpt' => __('Excerpt', 'strong-testimonials'));
    // 4. add custom fields
    foreach ($fields as $key => $field) {
        if ($field['admin_table']) {
            if ('post_title' == $field['name']) {
                continue;
            } elseif ('featured_image' == $field['name']) {
                $fields_to_add['thumbnail'] = __('Thumbnail', 'strong-testimonials');
            } else {
                $fields_to_add[$field['name']] = apply_filters('wpmtst_l10n', $field['label'], wpmtst_get_l10n_context('form-fields'), $field['name'] . ' : label');
            }
        }
    }
    // 5. add [category], [comments] and [date]
    // 'categories' is reserved by WordPress.
    if (wpmtst_get_category_list()) {
        $fields_to_add['category'] = __('Categories', 'strong-testimonials');
    }
    if ($comments) {
        $fields_to_add['comments'] = $comments;
    }
    $fields_to_add['date'] = __('Date', 'strong-testimonials');
    // Push other added columns like [search_exclude] to the end.
    $columns = array_merge(array_slice($columns, 0, $offset), $fields_to_add, array_slice($columns, $offset, null));
    return $columns;
}