コード例 #1
0
ファイル: api.php プロジェクト: 2030449c/farkol
 /**
  * Callback function for the 'template_redirect' hook.
  *
  * Set some framework global variables.
  *
  * @since 0.1.0
  */
 public function theme_redirect_cb()
 {
     /* WordPress global post and wp_query objects. */
     global $post, $wp_query;
     /* Framework globals. */
     global $pc_post_object;
     /* Current post object. */
     global $pc_is_front_page;
     /* Front page status. */
     global $pc_home_page;
     /* Home page status. */
     global $pc_post_id;
     /* Post ID. */
     global $pc_show_on_front;
     /* Store the front page reading setting. */
     global $pc_page_template;
     /* Store the page template used for the current page. */
     global $pc_global_column_layout;
     /* Correct column layout to use for current page. */
     global $pc_page_on_front;
     /* Get the template for the current page if one defined (i.e. won't be defined for category archive pages or 404 error pages). */
     if (!is_archive() && !is_404()) {
         $pc_page_template = basename(get_page_template());
     }
     $pc_post_object = $post;
     $pc_is_front_page = is_front_page();
     $pc_home_page = is_home();
     /* Test $wp-query->post property, and that it has a valid ID, as it may not always exist (i.e. on 404.php page, or search.php). */
     if (property_exists($wp_query, 'post') && isset($wp_query->post->ID)) {
         $pc_post_id = $wp_query->post->ID;
     }
     /* Modify the post ID if necessary. i.e. if 'A static page' has been selected on reading settings. In this case the post ID for the static page set for the blog posts will be invalid. */
     $pc_show_on_front = get_option('show_on_front');
     $pc_page_on_front = get_option('page_on_front');
     if ($pc_show_on_front == 'page') {
         /* If the 'Posts page'. */
         if (is_home()) {
             /* Use the 'page_for_posts' WP option to get the 'correct' ID for this page.
              * Otherwise all other attempts at getting the post ID results in the first ID
              * in the posts loop. */
             $pc_post_id = get_option('page_for_posts');
         }
     }
     /* Get the correct column layout to use for current page. */
     $options = get_option(PC_OPTIONS_DB_NAME);
     /* If current page is an archive OR front page with 'Your latest posts' OR front page
      * with reading settings set to static page but the front page drop down not set, then
      * use the default theme column layout. */
     if (is_archive() || $pc_is_front_page && $pc_show_on_front == 'posts' || $pc_home_page && $pc_page_on_front == 0) {
         $pc_global_column_layout = $options[PC_DEFAULT_LAYOUT_THEME_OPTION];
     } else {
         $pc_global_column_layout = get_post_meta($pc_post_id, '_' . PC_THEME_NAME_SLUG . '_column_layout', true);
     }
     if (empty($pc_global_column_layout) || $pc_global_column_layout == 'default') {
         $pc_global_column_layout = $options[PC_DEFAULT_LAYOUT_THEME_OPTION];
     }
     /* Set the global WordPress $content_width variable. */
     PC_Utility::set_content_width($pc_global_column_layout);
 }