public function valid()
 {
     // if views not active
     if (!defined('WPV_VERSION') || !function_exists('wpv_has_wordpress_archive')) {
         return false;
     }
     // get current type name
     $type = self::get_type_name();
     // check stored validation
     if (isset(self::$template_id[$type]) && self::$template_id[$type] !== null && self::$template_id[$type] !== false) {
         return true;
     }
     $archive = $type == 'post' ? wpv_has_wordpress_archive() : wpv_has_wordpress_archive('post', $type);
     self::$template_id[$type] = $archive && $archive !== 0 ? $archive : false;
     return self::$template_id[$type];
 }
 public function valid()
 {
     if (self::$template_id !== null && self::$template_id !== false) {
         return true;
     }
     // if views not active
     if (!defined('WPV_VERSION') || !function_exists('wpv_has_wordpress_archive')) {
         return false;
     }
     $cpt = Types_Helper_Condition::get_post_type();
     $archive = $cpt->name == 'post' ? wpv_has_wordpress_archive() : wpv_has_wordpress_archive('post', $cpt->name);
     if (!$archive && $archive === 0) {
         return false;
     }
     self::$template_id = $archive;
     return true;
 }
Example #3
0
/**
* has_wpv_wp_archive
*
* Official API for checking whether an archive loop has a WPA assigned.
*
* Alias for wpv_has_wordpress_archive
*
* @since 1.8.0
*/
function has_wpv_wp_archive($kind = 'other', $slug = 'home-blog')
{
    return wpv_has_wordpress_archive($kind, $slug);
}
Example #4
0
    public static function wpcf_access_show_error_list_ajax()
    {
        if (!current_user_can('manage_options')) {
            _e('There are security problems. You do not have permissions.', 'wpcf-access');
            die;
        }
        if (!isset($_POST['wpnonce']) || !wp_verify_nonce($_POST['wpnonce'], 'wpcf-access-error-pages')) {
            die('verification failed');
        }
        $post_type = sanitize_text_field($_POST['posttype']);
        $is_archive = sanitize_text_field($_POST['is_archive']);
        $out = '
			<form method="" id="wpcf-access-set_error_page">
				<input type="hidden" value="' . esc_attr($_POST['access_type']) . '" name="typename">
				<input type="hidden" value="' . esc_attr($_POST['access_value']) . '" name="valuename">';
        if ($is_archive == 1) {
            $out .= '<input type="hidden" value="' . esc_attr($_POST['access_archivetype']) . '" name="archivetypename">
				<input type="hidden" value="' . esc_attr($_POST['access_archivevalue']) . '" name="archivevaluename">';
        }
        $out .= '<h2>' . __('Single post error', 'wpcf-access') . '</h2>';
        $checked = isset($_POST['cur_type']) && $_POST['cur_type'] == '' ? ' checked="checked" ' : '';
        if ($_POST['forall'] != 1) {
            $out .= '
				<p>
					<label>
						<input type="radio" value="default" name="error_type" class="js-wpcf-access-type"' . $checked . '> ' . __('Default error', 'wpcf-access') . '
					</label>
				</p>';
        }
        $checked = isset($_POST['cur_type']) && $_POST['cur_type'] == 'error_404' ? ' checked="checked" ' : '';
        if ($_POST['forall'] == 1 && isset($_POST['cur_type']) && $_POST['cur_type'] == '') {
            $checked = ' checked="checked" ';
        }
        $out .= '
				<p>
					<label>
						<input type="radio" value="error_404" name="error_type"' . $checked . ' class="js-wpcf-access-type"> ' . __('Show 404 - page not found', 'wpcf-access') . '
					</label>
				</p>';
        if (class_exists('WP_Views') && !class_exists('WPDD_Layouts')) {
            $checked = isset($_POST['cur_type']) && $_POST['cur_type'] == 'error_ct' ? ' checked="checked" ' : '';
            $out .= '
				<p>
					<label>
						<input type="radio" value="error_ct" name="error_type"' . $checked . ' class="js-wpcf-access-type"> ' . __('Show Content Template', 'wpcf-access') . '
					</label>
					<select name="wpcf-access-ct" class="hidden" class="js-wpcf-error-ct-value">
						<option value="">' . __('None', 'wpcf-access') . '</option>';
            $wpv_args = array('post_type' => 'view-template', 'posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'title', 'post_status' => 'publish');
            $content_tempaltes = get_posts($wpv_args);
            foreach ($content_tempaltes as $post) {
                $selected = isset($_POST['cur_value']) && $_POST['cur_value'] == $post->ID ? ' selected="selected" ' : '';
                $out .= '
						<option value="' . esc_attr($post->ID) . '"' . $selected . '>' . $post->post_title . '</option>';
            }
            $out .= '
					</select>
				</p>';
        }
        $templates = wp_get_theme()->get_page_templates();
        if (!empty($templates)) {
            $checked = isset($_POST['cur_type']) && $_POST['cur_type'] == 'error_php' ? ' checked="checked" ' : '';
            $out .= '
				<p>
					<label>
						<input type="radio" value="error_php" name="error_type"' . $checked . ' class="js-wpcf-access-type"> ' . __('Show Page template', 'wpcf-access') . '
					</label>
					<select name="wpcf-access-php" class="hidden" class="js-wpcf-error-php-value">
						<option value="">' . __('None', 'wpcf-access') . '</option>';
            foreach ($templates as $template_name => $template_filename) {
                $selected = isset($_POST['cur_value']) && $_POST['cur_value'] == $template_filename ? ' selected="selected" ' : '';
                $out .= '<option value="' . esc_attr($template_filename) . '"' . $selected . '>' . $template_filename . '</option>';
            }
            $out .= '
					</select>
				</p>';
        }
        $show_php_tempaltes = true;
        if ($is_archive == 1) {
            $archive_out = '';
            //Hide php templates
            $show_php_tempaltes = true;
            $out .= '<h2>' . __('Archive error', 'wpcf-access') . '</h2>';
            if (class_exists('WP_Views') && function_exists('wpv_force_wordpress_archive') && !class_exists('WPDD_Layouts')) {
                global $WPV_view_archive_loop, $WP_Views;
                $have_archives = wpv_has_wordpress_archive('post', $post_type);
                if ($have_archives > 0) {
                    $show_php_tempaltes = false;
                    $checked = isset($_POST['cur_archivetype']) && $_POST['cur_archivetype'] == 'error_ct' ? ' checked="checked" ' : '';
                    $has_items = wpv_check_views_exists('archive');
                    if (count($has_items) > 0) {
                        $archive_out .= '<p><label>
							<input type="radio" value="error_ct" name="archive_error_type" ' . $checked . 'class="js-wpcf-access-type-archive">
							' . __('Choose a different WordPress archive for people without read permission', 'wpcf-access') . '<br />';
                        $custom_error = '';
                        $custom_error = '';
                        $view = get_post($have_archives);
                        if (is_object($view)) {
                            $has_items = array_diff($has_items, array($have_archives));
                            $custom_error = sprintf(__('This custom post archive displays with the WordPress Archive "%s".', 'wpcf-access'), esc_attr($view->post_title));
                        }
                        $archive_out .= '</label>';
                        $wpv_args = array('post_type' => 'view', 'post__in' => $has_items, 'posts_per_page' => -1, 'order' => 'ASC', 'orderby' => 'title', 'post_status' => 'publish');
                        $wpv_query = new WP_Query($wpv_args);
                        $wpv_count_posts = $wpv_query->post_count;
                        if ($wpv_count_posts > 0) {
                            $archive_out .= '<select name="wpcf-access-archive-ct" class="js-wpcf-error-ct-value">
							<option value="">' . __('None', 'wpcf-access') . '</option>';
                            while ($wpv_query->have_posts()) {
                                $wpv_query->the_post();
                                $post_id = get_the_id();
                                //$options = $WPV_view_archive_loop->_view_edit_options($post_id, $options);
                                $post = get_post($post_id);
                                $selected = isset($_POST['cur_archivevalue']) && $_POST['cur_archivevalue'] == $post->ID ? ' selected="selected" ' : '';
                                $archive_out .= '<option value="' . esc_attr($post->ID) . '" ' . $selected . '>' . $post->post_title . '</option>';
                            }
                            $archive_out .= '</select>';
                        }
                        $archive_out .= '<p class="toolset-alert toolset-alert- js-wpcf-error-ct-value-info" style="display: none; opacity: 1;">
								' . $custom_error . '</p>';
                        $archive_out .= '</p>';
                    } else {
                        $archive_out .= '<p>' . __('Sorry, no alternative WordPress Archives. First, create a new WordPress Archive, then return here to choose it.', 'wpcf-access') . '</p>';
                    }
                }
            }
            if ($show_php_tempaltes) {
                $theme_files = array();
                if (isset($_POST['cur_archivevalue'])) {
                    $_POST['cur_archivevalue'] = urldecode($_POST['cur_archivevalue']);
                    $_POST['cur_archivevalue'] = str_replace("\\\\", "\\", $_POST['cur_archivevalue']);
                }
                if (is_child_theme()) {
                    $child_theme_dir = get_stylesheet_directory();
                    $theme_files = self::wpcf_access_scan_dir($child_theme_dir, $theme_files);
                }
                $theme_dir = get_template_directory() . '/';
                if (file_exists($theme_dir . 'archive-' . $post_type . '.php')) {
                    $curent_file = 'archive-' . $post_type . '.php';
                } elseif (file_exists($theme_dir . 'archive.php')) {
                    $current_file = 'archive.php';
                } else {
                    $current_file = 'index.php';
                }
                $error_message = sprintf(__('This custom post archive displays with the PHP template "%s".', 'wpcf-access'), $current_file);
                $theme_files = self::wpcf_access_scan_dir($theme_dir, $theme_files, $current_file);
                $checked = isset($_POST['cur_archivetype']) && $_POST['cur_archivetype'] == 'error_php' ? ' checked="checked" ' : '';
                $archive_out .= '<p><label>
					<input type="radio" value="error_php" name="archive_error_type"' . $checked . ' class="js-wpcf-access-type-archive"> ' . __('Choose a different PHP template for people without read permission', 'wpcf-access') . '
					</label>
					<p class="toolset-alert toolset-alert- js-wpcf-error-php-value-info" style="display: none; opacity: 1;">
					' . $error_message . '
					</p><select name="wpcf-access-archive-php" class="js-wpcf-error-php-value hidden">
					<option value="">' . __('None', 'wpcf-access') . '</option>';
                for ($i = 0, $limit = count($theme_files); $i < $limit; $i++) {
                    $selected = isset($_POST['cur_archivevalue']) && $_POST['cur_archivevalue'] == $theme_files[$i] ? ' selected="selected" ' : '';
                    $archive_out .= '<option value="' . esc_attr($theme_files[$i]) . '" ' . $selected . '>' . preg_replace("/.*(\\/.*\\/)/", "\$1", $theme_files[$i]) . '</option>';
                }
                $archive_out .= '</select></p>';
            }
            //Default error, use for everyone if set.
            if ($_POST['forall'] != 1) {
                $checked = empty($checked) ? ' checked="checked" ' : '';
                $out .= '<p><label>
				<input type="radio" value="default" name="archive_error_type" class="js-wpcf-access-type-archive"' . $checked . '> ' . __('Default error', 'wpcf-access') . '
				</label></p>';
            }
            //Show post not found message'
            //Set post type not queryable
            $checked = isset($_POST['cur_archivetype']) && $_POST['cur_archivetype'] == 'default_error' || empty($checked) ? ' checked="checked" ' : '';
            $out .= '<p><label>
			<input type="radio" value="default_error" name="archive_error_type" class="js-wpcf-access-type-archive"' . $checked . '> ' . __('Display: "No posts found"', 'wpcf-access') . '
			</label></p>';
            $out .= $archive_out;
        }
        //End check if post type have archive
        $out .= '</form>';
        echo $out;
        die;
    }