/** * @hook */ public function template_include($template) { if (!apply_filters('metis.auth.is_forbidden', false)) { return $template; } return get_query_template('403'); }
/** * Overrides the default behavior of portfolio taxonomies to use the archive-portfolio template * http://www.billerickson.net/reusing-wordpress-theme-files/ * * @param string template path */ function portfoliopress_template_chooser($template) { global $wp_query; $portfolio = false; // Check if the taxonomy query contains only image or gallery post formats if (is_category() || is_tag() || is_home()) { $portfolio = true; if ($wp_query->have_posts()) { while ($wp_query->have_posts()) { $wp_query->the_post(); $format = get_post_format(); if ($format !== 'image' && $format != 'gallery') { $portfolio = false; } } } } // Check if template should be displayed as archive-portfolio.php if (is_post_type_archive('portfolio') || is_tax('post_format', 'post-format-image') || is_tax('post_format', 'post-format-gallery') || is_tax('portfolio_category') || is_tax('portfolio_tag')) { $portfolio = true; } // Use the archive-portfolio.php template if ($portfolio) { $wp_query->set('portfolio_view', true); $template = get_query_template('archive-portfolio'); } return $template; }
/** * @param $request */ function euzakupki_add_manual_funds_result($request) { if (!current_user_can('manage_options')) { global $wp_query; $wp_query->is_404 = true; $wp_query->is_single = false; $wp_query->is_page = false; include get_query_template('404'); exit; } global $wpdb; $customer = $wpdb->get_row('select * from wp_users where id = ' . $request['customer']); if (!$customer) { print_r(__('Клиент не найден', 'euzakupki')); exit; } if (empty($request['customer']) or !is_numeric($request['customer'])) { print_r(__('Параметр customer должен быть числом', 'euzakupki')); exit; } $customer_balance = get_user_meta($request['customer'], 'balance', true); if (!$customer_balance) { print_r(__('Баланс клиента не определен', 'euzakupki')); exit; } @($customer_balance = preg_replace('!s:(\\d+):"(.*?)";!e', "'s:'.strlen('\$2').':\"\$2\";'", $customer_balance)); $customer_balance = unserialize($customer_balance); $customer_balance = array_reverse($customer_balance); print_r(sprintf(__('ID клиента: %s' . "<br />", 'euzakupki'), $customer->ID)); print_r(sprintf(__('Емал: %s' . "<br />", 'euzakupki'), $customer->user_email)); print_r(sprintf(__('Дата и время пополнения: %s' . "<br />", 'euzakupki'), $customer_balance[0]['date'])); print_r(sprintf(__('Зачислена сумма: %s' . "<br />", 'euzakupki'), $customer_balance[0]['amount'])); exit; }
/** * @param $request */ function euzakupki_get_transactions($request) { if (!current_user_can('manage_options')) { global $wp_query; $wp_query->is_404 = true; $wp_query->is_single = false; $wp_query->is_page = false; include get_query_template('404'); exit; } global $wpdb; $customer = $wpdb->get_row('select * from wp_users where id = ' . $request['customer']); if (!$customer) { print_r(__('Клиент не найден', 'euzakupki')); exit; } if (empty($request['customer']) or !is_numeric($request['customer'])) { print_r(__('Параметр customer должен быть числом', 'euzakupki')); exit; } $customer_balance = get_user_meta($request['customer'], 'balance', true); $customer_balance = unserialize($customer_balance); debug($customer_balance); exit; }
/** * Make a 'reference' archive a thing in the template hierarchy. * * @param string $template The current template chosen. * @return string The template to use for this view. */ function archive_template($template) { if (!is_search() && !is_feed() && 'reference' === get_query_var('custom_archive')) { $archive_template = get_query_template('archive', array('archive-reference.php', 'archive.php')); $template = $archive_template ? $archive_template : $template; } return $template; }
function load_query_template($type, $templates = array()) { $located = get_query_template($type, $templates); if (!empty($located)) { load_template($located); } else { Core::log('Unable to locate template part \'' . $type . '\'.'); } }
function get_footer() { $template = get_query_template('footer'); if (!empty($template)) { load_template($template, true); } else { Core::log('Footer file missing for theme', YG_WARNING); } }
/** * Redirect the current query to WoordPress' 404 template. * * @global WP_Query $wp_query * * @uses get_query_template() */ public static function redirect_404() { // Display a 404 page since we don't have overviews global $wp_query; $wp_query->is_404 = true; $wp_query->is_single = false; $wp_query->is_page = false; include get_query_template('404'); exit; }
function szub_search_custom_template($template) { if (is_search() && szub_is_search_key() && file_exists(get_template_directory() . '/search-transcript.php')) { $template = get_template_directory() . '/search-transcript.php'; } if (!$template) { $template = get_query_template('search'); } return $template; }
function tw_print_template($template) { if (!tw_is_print()) { return $template; } // use the theme's print.php if it exists $template = get_query_template('print'); if (!$template) { $template = dirname(__FILE__) . '/print.php'; } return $template; }
public function vendor_page_template($page_template) { if (is_page('vendor')) { $username = get_query_var('username'); if (isset($username) && get_user_by('login', $username)) { $page_template = dirname(__FILE__) . '/views/vendor-page-template.php'; } else { $page_template = get_query_template('404'); } } if (is_page('vendors')) { $page_template = dirname(__FILE__) . '/views/vendor-search-template.php'; } return $page_template; }
function xsbf_is_fullwidth() { /* for pages, check the page template */ if (is_page() and (+is_page_template('page-fullpostsnoheader.php') or +is_page_template('page-fullwidth-noheader.php') or +is_page_template('page-fullwidth.php') or +is_page_template('page-fullwithposts.php') or +is_page_template('page-fullwithsubpages.php'))) { return true; /* for posts, check the single template */ } elseif (is_single()) { $current_template = get_single_template(); $fullwidth_template = get_query_template('single-fullwidth'); if ($current_template and $current_template == $fullwidth_template) { return true; } } return false; }
function force_404() { if (!is_admin()) { if (!is_home() && !is_page('about') && !is_page('random')) { $current_user = wp_get_current_user(); global $post; $author_id = $post->post_author; if (is_single() && $current_user->ID != $author_id) { status_header(404); nocache_headers(); include get_query_template('404'); die; //m**********r } } } }
protected function GetPostTemplate($post) { $id = $post->ID; $template = get_page_template_slug($id); $pagename = $post->post_name; $templates = array(); if ($template && 0 === validate_file($template)) { $templates[] = $template; } if ($pagename) { $templates[] = "page-{$pagename}.php"; } if ($id) { $templates[] = "page-{$id}.php"; } $templates[] = 'page.php'; return get_query_template('page', $templates); }
/** * Include store template * * @param type $template * @return string */ function store_template($template) { $store_name = get_query_var('store'); if (!empty($store_name)) { $store_user = get_user_by('slug', $store_name); // no user found if (!$store_user) { return get_404_template(); } // check if the user is seller if (!dokan_is_user_seller($store_user->ID)) { return get_404_template(); } $templates = array("store-{$store_name}.php", 'store.php'); return get_query_template('store', $templates); } return $template; }
/** * Retrieve path of attachment template in current or parent template. * * The attachment path first checks if the first part of the mime type exists. * The second check is for the second part of the mime type. The last check is * for both types separated by an underscore. If neither are found then the file * 'attachment.php' is checked and returned. * * Some examples for the 'text/plain' mime type are 'text.php', 'plain.php', and * finally 'text_plain.php'. * * @since 2.0.0 * * @return string */ function get_attachment_template() { global $posts; $type = explode('/', $posts[0]->post_mime_type); if ($template = get_query_template($type[0])) { return $template; } elseif ($template = get_query_template($type[1])) { return $template; } elseif ($template = get_query_template("{$type['0']}_{$type['1']}")) { return $template; } else { return get_query_template('attachment'); } }
/** * Retrieve path of attachment template in current or parent template. * * The attachment path first checks if the first part of the mime type exists. * The second check is for the second part of the mime type. The last check is * for both types separated by an underscore. If neither are found then the file * 'attachment.php' is checked and returned. * * Some examples for the 'text/plain' mime type are 'text.php', 'plain.php', and * finally 'text-plain.php'. * * The template path is filterable via the dynamic {@see '$type_template'} hook, * e.g. 'attachment_template'. * * @since 2.0.0 * * @see get_query_template() * * @global array $posts * * @return string Full path to attachment template file. */ function get_attachment_template() { $attachment = get_queried_object(); $templates = array(); if ($attachment) { if (false !== strpos($attachment->post_mime_type, '/')) { list($type, $subtype) = explode('/', $attachment->post_mime_type); } else { list($type, $subtype) = array($attachment->post_mime_type, ''); } if (!empty($subtype)) { $templates[] = "{$type}-{$subtype}.php"; $templates[] = "{$subtype}.php"; } $templates[] = "{$type}.php"; } $templates[] = 'attachment.php'; return get_query_template('attachment', $templates); }
/** * Hooks the WP filter single_template to deal with the shadow post * types for pages and singular templates, ensuring they use the * right template. * * @param string $template Path to a template file * @return Path to a template file **/ public function single_template($template) { if (bbl_is_default_lang()) { return $template; } // Deal with the language front pages and custom page templates $post = get_post(get_the_ID()); if ('page' == get_option('show_on_front')) { $front_page_transid = $this->get_transid(get_option('page_on_front')); $this_transid = $this->get_transid(get_the_ID()); // Check if this is a translation of the page on the front of the site if ($front_page_transid == $this_transid) { // global $wp_query, $wp; if ('page' == $this->get_base_post_type($post->post_type)) { if ($custom_page_template = get_post_meta(get_option('page_on_front'), '_wp_page_template', true)) { $templates = (array) $custom_page_template; } else { $templates = (array) 'page.php'; } if ($_template = locate_template($templates)) { return $_template; } } } } // Check if we're dealing with a page or a translation of a page if ('page' == $this->get_base_post_type($post->post_type)) { $custom_page_template = get_post_meta(get_the_ID(), '_wp_page_template', true); if ($custom_page_template && 'default' != $custom_page_template) { $templates = (array) $custom_page_template; } else { $templates = array('page.php'); } if ($_template = locate_template($templates)) { return $_template; } } $templates[] = "single-{$this->get_base_post_type($post->post_type)}.php"; $templates[] = "single.php"; $template = get_query_template('bbl-single', $templates); return $template; }
/** * Handles validation when somebody is attempting to view an invoice. * If validation is passsed, we add the necessary * filters to display the invoice header and page content; * Global $invoice_id variable set by WPI_Functions::validate_page_hash(); */ function template_redirect() { global $invoice_id, $wpi_settings, $wpi_invoice_object, $post, $current_user; //** Alwys load styles without checking if given page has an invoice */ wp_enqueue_style('wpi-theme-specific'); wp_enqueue_style('wpi-default-style'); //** Determine if the current page is invoice's page */ if (empty($post->ID) || $wpi_settings['web_invoice_page'] != $post->ID) { return; } //** If invoice_id is passed, run validate_page_hash to make sure this is the right page and invoice_id exists */ if (isset($_GET['invoice_id'])) { if (WPI_Functions::validate_page_hash(esc_sql($_GET['invoice_id']))) { //** load global invoice object */ $post_id = wpi_invoice_id_to_post_id($invoice_id); $wpi_invoice_object = new WPI_Invoice(); $wpi_invoice_object->load_invoice("id={$post_id}"); add_filter('viewable_invoice_types', array($this, 'viewable_types')); //** Determine if current invoice object is "viewable" */ if (!in_array($wpi_invoice_object->data['post_status'], apply_filters('viewable_invoice_types', array('active')))) { return; } if (isset($wpi_settings['logged_in_only']) && $wpi_settings['logged_in_only'] == 'true') { if (!current_user_can(WPI_UI::get_capability_by_level($wpi_settings['user_level'])) && !WPI_Functions::user_is_invoice_recipient($wpi_invoice_object)) { //** Show 404 when invoice doesn't exist */ $not_found = get_query_template('404'); require_once $not_found; die; } } //** Load front end scripts */ wp_enqueue_script('jquery.validate'); wp_enqueue_script('wpi-gateways'); wp_enqueue_script('jquery.maskedinput'); wp_enqueue_script('wpi-frontend-scripts'); if (!empty($wpi_settings['ga_event_tracking']) && $wpi_settings['ga_event_tracking']['enabled'] == 'true') { wp_enqueue_script('wpi-ga-tracking', WPI_URL . "/core/js/wpi.ga.tracking.js", array('jquery')); } //** Apply Filters to the invoice description */ add_action('wpi_description', 'wpautop'); add_action('wpi_description', 'wptexturize'); add_action('wpi_description', 'shortcode_unautop'); add_action('wpi_description', 'convert_chars'); add_action('wpi_description', 'capital_P_dangit'); //** Declare the variable that will hold our AJAX url for JavaScript purposes */ wp_localize_script('wpi-gateways', 'wpi_ajax', array('url' => admin_url('admin-ajax.php'))); add_action('wp_head', array('WPI_UI', 'frontend_header')); if ($wpi_settings['replace_page_title_with_subject'] == 'true' || $wpi_settings['hide_page_title'] == 'true') { add_action('wp_title', array('WPI_UI', 'wp_title'), 0, 3); } if ($wpi_settings['replace_page_heading_with_subject'] == 'true' || $wpi_settings['hide_page_title'] == 'true') { add_action('the_title', array('WPI_UI', 'the_title'), 0, 2); } add_action('the_content', array('WPI_UI', 'the_content'), 20); } else { //** Show 404 when invoice doesn't exist */ $not_found = get_query_template('404'); require_once $not_found; die; } } //** Fixed WordPress filters if page is being opened in HTTPS mode */ if (isset($_SERVER['HTTPS']) && $_SERVER["HTTPS"] == "on") { if (function_exists('force_ssl')) { add_filter('option_siteurl', 'force_ssl'); add_filter('option_home', 'force_ssl'); add_filter('option_url', 'force_ssl'); add_filter('option_wpurl', 'force_ssl'); add_filter('option_stylesheet_url', 'force_ssl'); add_filter('option_template_url', 'force_ssl'); add_filter('script_loader_src', 'force_ssl'); } } //** Lookup functionality */ if (isset($_POST['wp_invoice_lookup_input'])) { if (!empty($current_user->ID)) { $id = get_invoice_id($_POST['wp_invoice_lookup_input']); if (empty($id)) { //** Show 404 when invoice doesn't exist */ $not_found = get_query_template('404'); require_once $not_found; die; } $invoice = get_invoice($id); if (current_user_can('level_10') || $current_user->data->user_email == $invoice['user_email']) { header("location:" . get_invoice_permalink($_POST['wp_invoice_lookup_input'])); die; } else { //** Show 404 when invoice doesn't exist */ $not_found = get_query_template('404'); require_once $not_found; die; } } else { //** Show 404 when invoice doesn't exist */ $not_found = get_query_template('404'); require_once $not_found; die; } } }
public function index_template($template) { if ($replacement_template = get_query_template('index-' . get_query_var('post_type'))) { return $replacement_template; } return $template; }
/** * Display the attachment. * * Uses the new rewrite endpoint to get an attachment ID * and display the attachment if the currently logged in user * has the authorization to. * * @since 3.2.0 * @return void */ public function view_attachment() { $attachment_id = get_query_var('wpas-attachment'); if (!empty($attachment_id)) { $attachment = get_post($attachment_id); /** * Return a 404 page if the attachment ID * does not match any attachment in the database. */ if (empty($attachment)) { /** * @var WP_Query $wp_query WordPress main query */ global $wp_query; $wp_query->set_404(); status_header(404); include get_query_template('404'); die; } if ('attachment' !== $attachment->post_type) { wp_die(__('The file you requested is not a valid attachment', 'awesome-support')); } if (empty($attachment->post_parent)) { wp_die(__('The attachment you requested is not attached to any ticket', 'awesome-support')); } $parent = get_post($attachment->post_parent); // Get the parent. It can be a ticket or a ticket reply $parent_id = empty($parent->post_parent) ? $parent->ID : $parent->post_parent; if (true !== wpas_can_view_ticket($parent_id)) { wp_die(__('You are not allowed to view this attachment', 'awesome-support')); } $filename = basename($attachment->guid); ini_set('user_agent', 'Awesome Support/' . WPAS_VERSION . '; ' . get_bloginfo('url')); header("Content-Type: {$attachment->post_mime_type}"); header("Content-Disposition: inline; filename=\"{$filename}\""); readfile($attachment->guid); die; } }
/** * Set the template to use, buffers the needed template parts * and resets post vars. * * @package WP Idea Stream * @subpackage core/template-loader * * @since 2.0.0 * * @global $wp_query * @param string $template name of the template to use * @uses is_buddypress() to bail early if it's this plugin's territory * @uses wp_idea_stream_get_idea_var() to get a globalized var * @uses is_404() to check for a 404 * @uses get_query_template() to get a specific template * @uses get_index_template() to get the index template * @uses wp_idea_stream_set_idea_var() to set a globalized var * @uses is_post_type_archive() to check if it's ideas post type archive * @uses wp_idea_stream_get_post_type() to get ideas post type identifier * @uses set_query_var() to get a query var * @uses remove_all_filters() to remove all filters on a specific hook * @uses wp_idea_stream_reset_post() to reset WordPress $post global and avoid notices * @uses wp_idea_stream_reset_post_title() to reset the title depending on the context * @uses wp_idea_stream_buffer_template_part() to buffer the content to display * @uses wp_idea_stream_is_edit() to check if the idea is to be edited * @uses wp_idea_stream_ideas_lock_idea() to check if the idea to edit is not currently edited by another user * @uses wp_idea_stream_add_message() to give a user some feedback * @uses wp_idea_stream_ideas_can_edit() to check current user can edit an idea * @uses wp_safe_redirect() to safely redirect the user * @uses wp_idea_stream_get_redirect_url() to get the default redirect url * @uses wp_idea_stream_buffer_single_idea() to buffer the idea content to display * @uses do_action() Calls 'wp_idea_stream_set_core_template' to perform actions once a core template is set * Calls 'wp_idea_stream_set_single_template' to perform actions relative to the single idea template * Calls 'wp_idea_stream_set_template' to perform actions when no template matched * @uses apply_filters() Calls 'wp_idea_stream_template_args' to override template args in case of custom idea action * Calls 'wp_idea_stream_single_template_args' to override single template args * @return string $template. */ function wp_idea_stream_set_template($template = '') { global $wp_query; /** * Bail if BuddyPress, we'll use its theme compatibility * feature. */ if (function_exists('is_buddypress') && is_buddypress()) { return $template; } if (wp_idea_stream_get_idea_var('is_ideastream') && !is_404()) { // Try to see if the theme has a specific template for WP Idea Stream $template = get_query_template('ideastream'); if (empty($template)) { // else Try the page template $template = get_query_template('page', array('page.php')); } if (empty($template)) { // finally fall back to the index template $template = get_index_template(); } // Define it into plugin's vars wp_idea_stream_set_idea_var('template_file', $template); /** * First get results of the main query if not on a single idea. * and build plugin's main_query var. */ if (!wp_idea_stream_is_single_idea()) { wp_idea_stream_set_idea_var('main_query', array('ideas' => $wp_query->posts, 'total' => $wp_query->found_posts, 'query_vars' => array('author' => $wp_query->query_vars['author'], 'per_page' => $wp_query->query_vars['posts_per_page'], 'page' => !empty($wp_query->query_vars['paged']) ? $wp_query->query_vars['paged'] : 1, 'search' => $wp_query->query_vars['s'], 'exclude' => $wp_query->query_vars['post__not_in'], 'include' => $wp_query->query_vars['post__in'], 'orderby' => !empty($wp_query->query_vars['orderby']) ? $wp_query->query_vars['orderby'] : 'date', 'order' => $wp_query->query_vars['order'], 'meta_query' => $wp_query->meta_query->queries, 'tax_query' => $wp_query->tax_query->queries))); // Resetting the 's' query var now we got main query's result. set_query_var('s', ''); // Init template args $template_args = array('post_title' => '', 'comment_status' => 'closed', 'is_archive' => true, 'is_tax' => false, 'template_slug' => 'archive', 'template_name' => '', 'context' => ''); // Main plugin's archive page if (is_post_type_archive(wp_idea_stream_get_post_type())) { $template_args['context'] = 'archive'; } // Category / tag archive pages if (wp_idea_stream_get_idea_var('is_category') || wp_idea_stream_get_idea_var('is_tag')) { $template_args['is_tax'] = true; $template_args['context'] = 'taxonomy'; } // User's profile pages if (wp_idea_stream_get_idea_var('is_user')) { $template_args['template_slug'] = 'user'; $template_args['template_name'] = 'profile'; $template_args['context'] = 'user-profile'; } if (wp_idea_stream_get_idea_var('is_action')) { $template_args['is_archive'] = false; // New idea form if (wp_idea_stream_is_addnew()) { $template_args['template_slug'] = 'idea'; $template_args['template_name'] = 'form'; $template_args['context'] = 'new-idea'; } else { if (wp_idea_stream_is_signup()) { $template_args['template_slug'] = 'signup'; $template_args['context'] = 'signup'; // Allow plugins to add custom action } else { if (has_filter('wp_idea_stream_template_args')) { /** * Custom action ? * * @param array $template_args the template arguments used to reset the post */ $template_args = apply_filters('wp_idea_stream_template_args', $template_args); } } } } // Reset WordPress $post global. wp_idea_stream_reset_post(array('ID' => 0, 'post_title' => wp_idea_stream_reset_post_title($template_args['context']), 'post_author' => 0, 'post_date' => 0, 'post_type' => 'ideas', 'post_status' => 'publish', 'is_archive' => $template_args['is_archive'], 'comment_status' => $template_args['comment_status'], 'post_password' => false, 'is_tax' => $template_args['is_tax'])); /** * Internally used to redirect to BuddyPress member's profile * if needed * * @param string $context to help choosing the best template to use */ do_action('wp_idea_stream_set_core_template', $template_args['context'], $template_args); } else { $query_loop = new stdClass(); $query_loop->idea = $wp_query->post; // Should we use a custom template for single ideas ? $specific_single_template = get_query_template('single-ideastream'); if (!empty($specific_single_template)) { $template = $specific_single_template; } // Populate the global query loop with current idea wp_idea_stream_set_idea_var('query_loop', $query_loop); // Add the id to globals wp_idea_stream_set_idea_var('single_idea_id', $wp_query->post->ID); // Are we editing an idea ? if (wp_idea_stream_is_edit()) { // Check if the idea is currently being edited by someone else $user_is_editing = wp_idea_stream_ideas_lock_idea($query_loop->idea->ID); if (!empty($user_is_editing)) { wp_idea_stream_add_message(array('type' => 'info', 'content' => sprintf(__('The idea: "%s" is already being edited by another user.', 'wp-idea-stream'), $query_loop->idea->post_title))); // Redirect the user wp_safe_redirect(wp_idea_stream_get_redirect_url()); exit; } // Bail if user can't edit the idea if (!wp_idea_stream_ideas_can_edit($query_loop->idea)) { wp_idea_stream_add_message(array('type' => 'error', 'content' => __('You are not allowed to edit this idea.', 'wp-idea-stream'))); // Redirect the user wp_safe_redirect(wp_idea_stream_get_redirect_url()); exit; } // Inform the idea is to display in an edit form $query_loop->idea->is_edit = true; $template_args = array('template_slug' => 'idea', 'template_name' => 'form', 'context' => 'edit-idea'); $single_args = array('ID' => 0, 'post_title' => wp_idea_stream_reset_post_title($template_args['context']), 'post_author' => 0, 'post_date' => 0, 'post_type' => 'ideas', 'post_status' => 'publish', 'is_archive' => false, 'comment_status' => false, 'post_password' => false); // Or simply viewing one ? } else { $template_args = array('context' => 'single-idea'); $single_args = array('is_single' => true); } /** * @param array $single_args the single arguments used to reset the post */ wp_idea_stream_reset_post(apply_filters('wp_idea_stream_single_template_args', $single_args)); /** * Internally used to redirect to Buddypress Group's * single idea template if needed * * @param WP_Post $query_loop->idea the idea to display */ do_action('wp_idea_stream_set_single_template', $query_loop->idea, $template_args); } } /** * No IdeaStream template matched */ do_action('wp_idea_stream_set_template'); return $template; }
/** * Retrieve path of comment popup template in current or parent template. * * Checks for comment popup template in current template, if it exists or in the * parent template. * * @since 1.5.0 * @uses apply_filters() Calls 'comments_popup_template' filter on path. * * @return string */ function get_comments_popup_template() { $template = get_query_template('comments_popup', array('comments-popup.php')); // Backward compat code will be removed in a future release if ('' == $template) { $template = ABSPATH . WPINC . '/theme-compat/comments-popup.php'; } return $template; }
/** * Set a 404 error. * * Forces the given page to a WordPress 404 error. * * @since 4.0.0 * * @return void */ public static function set_404() { global $wp_query; status_header(404); if (function_exists('nocache_headers')) { nocache_headers(); } $wp_query->set_404(); $page_404 = get_404_template(); if (1 < strlen($page_404)) { include $page_404; } else { include get_query_template('index'); } die; }
/** * @expectedDeprecated get_themes * @expectedDeprecated get_current_theme */ function test_switch_theme() { $themes = get_themes(); // Switch to each theme in sequence. // Do it twice to make sure we switch to the first theme, even if it's our starting theme. // Do it a third time to ensure switch_theme() works with one argument. for ($i = 0; $i < 3; $i++) { foreach ($themes as $name => $theme) { // switch to this theme if ($i === 2) { switch_theme($theme['Template'], $theme['Stylesheet']); } else { switch_theme($theme['Stylesheet']); } $this->assertEquals($name, get_current_theme()); // make sure the various get_* functions return the correct values $this->assertEquals($theme['Template'], get_template()); $this->assertEquals($theme['Stylesheet'], get_stylesheet()); $root_fs = get_theme_root(); $this->assertTrue(is_dir($root_fs)); $root_uri = get_theme_root_uri(); $this->assertTrue(!empty($root_uri)); $this->assertEquals($root_fs . '/' . get_stylesheet(), get_stylesheet_directory()); $this->assertEquals($root_uri . '/' . get_stylesheet(), get_stylesheet_directory_uri()); $this->assertEquals($root_uri . '/' . get_stylesheet() . '/style.css', get_stylesheet_uri()); # $this->assertEquals($root_uri . '/' . get_stylesheet(), get_locale_stylesheet_uri()); $this->assertEquals($root_fs . '/' . get_template(), get_template_directory()); $this->assertEquals($root_uri . '/' . get_template(), get_template_directory_uri()); //get_query_template // template file that doesn't exist $this->assertEquals('', get_query_template(rand_str())); // template files that do exist //foreach ($theme['Template Files'] as $path) { //$file = basename($path, '.php'); // FIXME: untestable because get_query_template uses TEMPLATEPATH //$this->assertEquals('', get_query_template($file)); //} // these are kind of tautologies but at least exercise the code $this->assertEquals(get_404_template(), get_query_template('404')); $this->assertEquals(get_archive_template(), get_query_template('archive')); $this->assertEquals(get_author_template(), get_query_template('author')); $this->assertEquals(get_category_template(), get_query_template('category')); $this->assertEquals(get_date_template(), get_query_template('date')); $this->assertEquals(get_home_template(), get_query_template('home', array('home.php', 'index.php'))); $this->assertEquals(get_page_template(), get_query_template('page')); $this->assertEquals(get_paged_template(), get_query_template('paged')); $this->assertEquals(get_search_template(), get_query_template('search')); $this->assertEquals(get_single_template(), get_query_template('single')); $this->assertEquals(get_attachment_template(), get_query_template('attachment')); // this one doesn't behave like the others if (get_query_template('comments-popup')) { $this->assertEquals(get_comments_popup_template(), get_query_template('comments-popup')); } else { $this->assertEquals(get_comments_popup_template(), ABSPATH . 'wp-includes/theme-compat/comments-popup.php'); } $this->assertEquals(get_tag_template(), get_query_template('tag')); // nb: this probably doesn't run because WP_INSTALLING is defined $this->assertTrue(validate_current_theme()); } } }
/** * Choose appropriate template file when paged and not default language * * Some fix when somebody uses 'page_on_front', set page with custom Template, * this page has Loop of posts. Before that, when you changed language to * non-default and paged, WPML looses page Template and uses index.php from theme * * @since 3.1.5 * * @param string $template Template path retrieved from @see wp-includes/template-loader.php * * @return string New template path (or default) * */ function icl_template_paged($template) { global $wp_query, $sitepress; // we don't want to run this on default language if (ICL_LANGUAGE_CODE == icl_get_default_language()) { return $template; } // seems WPML overwrite 'page' param too early, let's fix this if ($sitepress->get_setting('language_negotiation_type') == 3) { set_query_var('page', get_query_var('paged')); } // if template is chosen correctly there is no need to change it if ($template != get_home_template()) { return $template; } // this is a place where real error occurs. on paged page result we loose // $wp_query->queried_object. so if it set correctly, there is no need to // change template if ($wp_query->get_queried_object() != null) { return $template; } // does our site really use custom page as front page? if (1 > intval(get_option('page_on_front'))) { return $template; } // get template slug for custom page chosen as front page $template_slug = get_page_template_slug(get_option('page_on_front')); // "The function get_page_template_slug() returns an empty string when the value of '_wp_page_template' is either empty or 'default'." if (!$template_slug) { return $template; } $templates = array(); $templates[] = $template_slug; $template = get_query_template('page', $templates); return $template; }
/** * wpsc_get_product_template function. * * @since 3.8 * @access public * @return void */ function wpsc_get_template($template) { return get_query_template($template); }
/** * Display the attachment. * * Uses the new rewrite endpoint to get an attachment ID * and display the attachment if the currently logged in user * has the authorization to. * * @since 3.2.0 * @return void */ public function view_attachment() { $attachment_id = get_query_var('wpas-attachment'); if (!empty($attachment_id)) { $attachment = get_post($attachment_id); /** * Return a 404 page if the attachment ID * does not match any attachment in the database. */ if (empty($attachment)) { /** * @var WP_Query $wp_query WordPress main query */ global $wp_query; $wp_query->set_404(); status_header(404); include get_query_template('404'); die; } if ('attachment' !== $attachment->post_type) { wp_die(__('The file you requested is not a valid attachment', 'wpas')); } if (empty($attachment->post_parent)) { wp_die(__('The attachment you requested is not attached to any ticket', 'wpas')); } $parent = get_post($attachment->post_parent); // Get the parent. It can be a ticket or a ticket reply $parent_id = empty($parent->post_parent) ? $parent->ID : $parent->post_parent; if (true !== wpas_can_view_ticket($parent_id)) { wp_die(__('You are not allowed to view this attachment', 'wpas')); } header("Content-Type: {$attachment->post_mime_type}"); readfile($attachment->guid); die; } }
function check_if_endpoint_exists($q) { global $wp_query; $my_account_id = wc_get_page_id('myaccount'); $current_id = $q->query_vars['page_id']; if (!$current_id) { $current_id = $q->queried_object_id; } if (!$q->is_404 && $current_id == $my_account_id && $q->is_page) { $uri_vars = array_filter(explode('/', $_SERVER['REQUEST_URI'])); $endpoints = WC()->query->get_query_vars(); $endpoint_in_url = urldecode(end($uri_vars)); $endpoints['shipping'] = urldecode($this->get_translated_edit_address_slug('shipping')); $endpoints['billing'] = urldecode($this->get_translated_edit_address_slug('billing')); if (urldecode($q->query['pagename']) != $endpoint_in_url && !in_array($endpoint_in_url, $endpoints) && is_numeric($endpoint_in_url) && !in_array(urldecode(prev($uri_vars)), $q->query_vars)) { $wp_query->set_404(); status_header(404); include get_query_template('404'); die; } } }
/** * category galleries for all */ function gridsby_gallery_template_chooser($template) { // Check if the taxonomy query contains only image formats if (is_category() || is_tag()) { $gallery_view = true; global $wp_query; if ($wp_query->have_posts()) { while ($wp_query->have_posts()) { $wp_query->the_post(); $format = get_post_format(); if ($format != 'image') { $gallery_view = false; } } } if ($gallery_view) { // gallery template $template = get_query_template('archive-image'); } } return $template; }