Ejemplo n.º 1
0
 /**
  * Shows a notice if any of the AWPCP pages shares its name with the
  * dynamic page View Categories.
  *
  * If a page share its name with the View Categories page, that page
  * will become unreachable.
  *
  * @since 3.0.2
  */
 public function check_duplicate_page_names()
 {
     global $wpdb;
     $view_categories_option = 'view-categories-page-name';
     $view_categories = sanitize_title(awpcp_get_page_name($view_categories_option));
     $view_categories_url = awpcp_get_view_categories_url();
     $duplicates = array();
     $awpcp_pages = array();
     $wp_pages = array();
     $posts = get_posts(array('post_type' => 'page', 'name' => $view_categories));
     foreach ($posts as $post) {
         if ($view_categories_url == get_permalink($post->ID)) {
             $duplicates[] = $post;
         }
     }
     $pages = empty($duplicates) ? array() : awpcp_get_plugin_pages_refs();
     foreach ($duplicates as $page) {
         if (isset($pages[$page->ID])) {
             $awpcp_pages[] = ucwords(awpcp()->settings->get_option_label($pages[$page->ID]->page));
         } else {
             $wp_pages[] = $page->post_title;
         }
     }
     if (!empty($awpcp_pages) || !empty($wp_pages)) {
         $view_categories_label = awpcp()->settings->get_option_label($view_categories_option);
         $view_categories_label = sprintf('<strong>%s</strong>', ucwords($view_categories_label));
     }
     if (!empty($awpcp_pages)) {
         $duplicated_pages = '<strong>' . join('</strong>, <strong>', $awpcp_pages) . '</strong>';
         $message = _n(count($awpcp_pages), '%1$s has the same name as the %2$s. That will cause %1$s to become unreachable. Please make sure you don\'t have duplicate page names.', '%1$s have the same name as the %2$s. That will cause %1$s to become unreachable. Please make sure you don\'t have duplicate page names.', 'AWPCP');
         $message = sprintf($message, $duplicated_pages, $view_categories_label);
         echo awpcp_print_error($message);
     }
     if (!empty($wp_pages)) {
         $duplicated_pages = '<strong>' . join('</strong>, <strong>', $wp_pages) . '</strong>';
         $message = _n(count($wp_pages), 'Page %1$s has the same name as the AWPCP %2$s. That will cause WordPress page %1$s to become unreachable. The %2$s is dynamic; you don\'t need to create a real WordPress page to show the list of cateogries, the plugin will generate it for you. If the WordPress page was created to show the default list of AWPCP categories, you can delete it and this error message will go away. Otherwise, please make sure you don\'t have duplicate page names.', 'Pages %1$s have the same name as the AWPCP %2$s. That will cause WordPress pages %1$s to become unreachable. The %2$s is dynamic; you don\'t need to create a real WordPress page to show the list of cateogries, the plugin will generate it for you. If the WordPress pages were created to show the default list of AWPCP categories, you can delete them and this error message will go away. Otherwise, please make sure you don\'t have duplicate page names.', 'AWPCP');
         $message = sprintf($message, $duplicated_pages, $view_categories_label);
         echo awpcp_print_error($message);
     }
 }
Ejemplo n.º 2
0
 /**
  * Check if the current page is one of the AWPCP pages.
  *
  * @since 3.4
  */
 function is_awpcp_page($page_id = null)
 {
     global $wp_the_query;
     if (!$wp_the_query) {
         return false;
     }
     $pages_refs = awpcp_get_plugin_pages_refs();
     if (is_null($page_id)) {
         $page_id = $wp_the_query->get_queried_object_id();
     }
     return isset($pages_refs[$page_id]);
 }