示例#1
0
 public function test_remove_query_var()
 {
     $public_qv_count = count($this->wp->public_query_vars);
     $this->wp->add_query_var('test');
     $this->assertTrue(in_array('test', $this->wp->public_query_vars));
     $this->wp->remove_query_var('test');
     $this->assertSame($public_qv_count, count($this->wp->public_query_vars));
 }
示例#2
0
 /**
  * Executes actions associated with selected page.
  */
 public function action()
 {
     if (isset($_POST['action']) && $_POST['action'] == 'add-to-cart') {
         /** @var \Jigoshop\Entity\Product $product */
         $product = $this->productService->find($_POST['item']);
         try {
             /** @var Item $item */
             $item = $this->wp->applyFilters('jigoshop\\cart\\add', null, $product);
             if ($item === null) {
                 throw new Exception(__('Unable to add product to the cart.', 'jigoshop'));
             }
             if (isset($_POST['quantity'])) {
                 $item->setQuantity($_POST['quantity']);
             }
             /** @var Cart $cart */
             $cart = $this->cartService->get($this->cartService->getCartIdForCurrentUser());
             $cart->addItem($item);
             $this->cartService->save($cart);
             $url = false;
             $button = '';
             switch ($this->options->get('shopping.redirect_add_to_cart')) {
                 case 'cart':
                     $url = $this->wp->getPermalink($this->options->getPageId(Pages::CART));
                     break;
                 case 'checkout':
                     $url = $this->wp->getPermalink($this->options->getPageId(Pages::CHECKOUT));
                     break;
                     /** @noinspection PhpMissingBreakStatementInspection */
                 /** @noinspection PhpMissingBreakStatementInspection */
                 case 'product_list':
                     $url = $this->wp->getPermalink($this->options->getPageId(Pages::SHOP));
                 case 'product':
                 case 'same_page':
                 default:
                     $button = sprintf('<a href="%s" class="btn btn-warning pull-right">%s</a>', $this->wp->getPermalink($this->options->getPageId(Pages::CART)), __('View cart', 'jigoshop'));
             }
             $this->messages->addNotice(sprintf(__('%s successfully added to your cart. %s', 'jigoshop'), $product->getName(), $button));
             if ($url !== false) {
                 $this->messages->preserveMessages();
                 $this->wp->wpRedirect($url);
             }
         } catch (NotEnoughStockException $e) {
             if ($e->getStock() == 0) {
                 $message = sprintf(__('Sorry, we do not have "%s" in stock.', 'jigoshop'), $product->getName());
             } else {
                 if ($this->options->get('products.show_stock')) {
                     $message = sprintf(__('Sorry, we do not have enough "%s" in stock to fulfill your order. We only have %d available at this time. Please edit your cart and try again. We apologize for any inconvenience caused.', 'jigoshop'), $product->getName(), $e->getStock());
                 } else {
                     $message = sprintf(__('Sorry, we do not have enough "%s" in stock to fulfill your order. Please edit your cart and try again. We apologize for any inconvenience caused.', 'jigoshop'), $product->getName());
                 }
             }
             $this->messages->addError($message);
         } catch (Exception $e) {
             $this->messages->addError(sprintf(__('A problem ocurred when adding to cart: %s', 'jigoshop'), $e->getMessage()));
         }
     }
 }
 /**
  * @param string $path
  *
  * @return string
  */
 public function parse_request($path)
 {
     global $wp_filter;
     $tmp_wp_filter = $wp_filter;
     $GLOBALS['wp_filter'] = array();
     $result = $path;
     $this->wp->parse_request();
     if ($this->wp->matched_rule) {
         $result = $this->wp->matched_rule;
         $this->wp->matched_rule = null;
     }
     $GLOBALS['wp_filter'] = $tmp_wp_filter;
     return $result;
 }
示例#4
0
 /**
  * Test method for the <code>#toJSON()</code> function.
  */
 public function testToJSON()
 {
     $array = WP::create()->setBackbackground('/Resources/Green.jpg')->setBackcontent('back content')->setBackground('/Resources/Red.jpg')->setBacktitle('back title')->setCount(3)->setType('Tile')->toJSON();
     $this->assertCount(6, $array);
     $this->assertEquals('/Resources/Green.jpg', $array['wp_backbackground']);
     $this->assertEquals('back content', $array['wp_backcontent']);
     $this->assertEquals('/Resources/Red.jpg', $array['wp_background']);
     $this->assertEquals('back title', $array['wp_backtitle']);
     $this->assertEquals(3, $array['wp_count']);
     $this->assertEquals('Tile', $array['wp_type']);
 }
示例#5
0
 function CreateInputs(WP $WP)
 {
     $typenow = $WP->typenow;
     $date_range_input = false;
     $settings = $WP->getSettings($typenow);
     if (!isset($settings['config'])) {
         return false;
     }
     if ($this->_isAuthorFilterNeeded($settings['config'])) {
         $this->_CreateAuthorInput($WP);
     }
     if ($this->_isDateFilterNeeded($settings['config'])) {
         $date_range_input = true;
         $this->_CreateDateInput($WP);
     }
     if ($this->_isTaxonomyFilterNeeded($settings['config'])) {
         $this->_CreateTaxonomyInputs($WP, $settings);
     }
     if ($WP->removeDefaultFilter() || $date_range_input) {
         printf('<span class="ex-filter" id="ex-filter-setting-input">%s</span>', json_encode($settings));
     }
     return true;
 }
示例#6
0
    /**
     * Get the \mysqli_result requested by $this->workingQ instated by either $this->get() | $this->prep().
     *
     *
     * @param string $limit The limit to apply to the $this->workingQ.
     *
     * @return \mysqli_result
     */
    public function data($limit = '')
    {
        $sel = substr(ltrim($this->workingQ), 0, 6);
        if ($sel == 'SELECT') {
            return \DB::query($this->workingQ);
        }
        //if
        return \DB::query('
            SELECT 
            p.*,
            DATE_FORMAT(p.post_date,"' . \WP::settings('date_format') . '") AS format_date, 
            t.name,
            t.slug,
            c.name AS category,
            c.slug AS category_slug
            FROM (
                SELECT 
                p.ID AS post_id,
                p.post_date,
                p.post_content,
                p.post_excerpt,
                p.post_title,
                p.post_name,
                u.display_name,
                u.user_nicename
                FROM wp_posts AS p
                INNER JOIN wp_users AS u ON u.ID=p.post_author
                WHERE p.post_status="publish" AND p.post_type="post"
                ' . $this->workingQ . $limit . ' 

            ) AS p
            LEFT JOIN wp_term_relationships AS wptr ON wptr.object_id=p.post_id
            LEFT JOIN wp_term_taxonomy AS wptt ON wptt.term_taxonomy_id=wptr.term_taxonomy_id
            LEFT JOIN wp_terms AS t ON t.term_id=wptt.term_id
            LEFT JOIN wp_term_taxonomy AS wptt_category ON wptt_category.term_taxonomy_id=wptr.term_taxonomy_id AND wptt_category.taxonomy="category"
            LEFT JOIN wp_terms AS c ON c.term_id=wptt_category.term_id
            ORDER BY p.post_date DESC
        ');
    }
 * @global object $wp_query
 * @since 1.5.0
 */
$wp_query = $wp_the_query;
/**
 * Holds the WordPress Rewrite object for creating pretty URLs
 * @global object $wp_rewrite
 * @since 1.5.0
 */
$GLOBALS['wp_rewrite'] = new WP_Rewrite();
/**
 * WordPress Object
 * @global object $wp
 * @since 2.0.0
 */
$wp = new WP();
/**
 * WordPress Widget Factory Object
 * @global object $wp_widget_factory
 * @since 2.8.0
 */
$GLOBALS['wp_widget_factory'] = new WP_Widget_Factory();
/**
 * WordPress User Roles
 * @global object $wp_roles
 * @since 2.0.0
 */
$GLOBALS['wp_roles'] = new WP_Roles();
do_action('setup_theme');
// Define the template related constants.
wp_templating_constants();
 /**
  * Called when the main execute function gets a 404 to check against old 
  * permalink structures and perform redirect if an old post can be 
  * matched.
  */
 function redirect_old_permalink($req_uri)
 {
     global $wp_query, $wp_rewrite;
     global $wp_version;
     $rules = get_option('permalink_redirect_rules');
     if (!$rules) {
         return;
     }
     // Backing up the rewrite object for you, imperative programmers!
     $wp_rewrite_old = $wp_rewrite;
     // Unsetting the globals. Argh! Evil global variables!
     foreach ($wp_query->query_vars as $key => $val) {
         unset($GLOBALS[$key]);
     }
     // Going through the rules.
     foreach ($rules as $rules2) {
         $wp2 = new WP();
         $wp_rewrite = new YLSY_Rewrite();
         $wp_rewrite->index = $wp_rewrite_old->index;
         $wp_rewrite->rules = $rules2;
         $wp2->parse_request();
         if (isset($wp2->query_vars['error']) && $wp2->query_vars['error'] == 404) {
             continue;
         }
         $query = new WP_Query();
         if ($wp_version >= '2.1') {
             $posts = $query->query($wp2->query_vars);
         } else {
             $wp2->build_query_string();
             $posts = $query->query($wp2->query_string);
         }
         if (count($posts) > 0) {
             $wp_rewrite = $wp_rewrite_old;
             $this->execute2($query, false);
             return;
         }
     }
     // Restoring global variables. We don't bother to reset the other
     // variables as we are going to do a 404 anyway.
     $wp_rewrite = $wp_rewrite_old;
 }
 /**
  * Determines the referer taxonomy
  * 
  * @return string|bool Either the name of the taxonomy to use or false if a referer taxonomy wasn't found
  */
 protected function determine_taxonomy()
 {
     global $wp;
     //Backup the server request variable
     $bk_req = $_SERVER['REQUEST_URI'];
     //Now set the request URL to the referrer URL
     //Could just chain the [1] selection, but that's not PHP5.3 compatible
     $url_split = explode(home_url(), esc_url(wp_get_referer()));
     if (isset($url_split[1])) {
         $_SERVER['REQUEST_URI'] = $url_split[1];
     } else {
         return false;
     }
     //Create our own new instance of WP, and have it parse our faux request
     $bcn_wp = new WP();
     //Copy over the current global wp object's query_vars since CPTs and taxonomies are added directly to the global $wp
     $bcn_wp->public_query_vars = $wp->public_query_vars;
     $bcn_wp->parse_request();
     $_SERVER['REQUEST_URI'] = $bk_req;
     if (is_array($bcn_wp->query_vars)) {
         foreach ($bcn_wp->query_vars as $query_var => $value) {
             if ($taxonomy = $this->query_var_to_taxonomy($query_var)) {
                 return $taxonomy;
             }
         }
     }
     return false;
 }
 public static function ids_from_url($url)
 {
     global $wp;
     $wp = new WP();
     //We need to cheat telling WP we are not in admin area to parse the URL properly
     $current_uri = $_SERVER['REQUEST_URI'];
     $self = $_SERVER['PHP_SELF'];
     $get = $_GET;
     global $current_screen;
     if ($current_screen) {
         $stored_current_screen = $current_screen->id;
     } else {
         require_once ABSPATH . '/wp-admin/includes/screen.php';
         $current_screen = WP_Screen::get('front');
     }
     $_SERVER['REQUEST_URI'] = $url;
     $_SERVER['PHP_SELF'] = 'foo';
     $urlParts = explode('?', $url);
     if (count($urlParts) > 1) {
         parse_str($urlParts[1], $_GET);
     }
     $wp->parse_request();
     $query = new WP_Query($wp->query_vars);
     $query->parse_query();
     //Set the global post in case that no-one is set and we have a single query
     global $post;
     if (!$post && $query->have_posts() && $query->is_singular()) {
         $post = $query->next_post();
         setup_postdata($post);
     }
     //Make the query accessible to add it to the response
     global $upfront_ajax_query;
     $upfront_ajax_query = clone $query;
     // Intercept /edit/(post|page)/id
     $editor = Upfront_ContentEditor_VirtualPage::serve();
     if ($editor->parse_page()) {
         global $wp_query;
         $query = $wp_query;
         $post = $wp_query->next_post();
         setup_postdata($post);
     }
     $_SERVER['REQUEST_URI'] = $current_uri;
     $_SERVER['PHP_SELF'] = $self;
     $_GET = $get;
     if (isset($stored_current_screen)) {
         //$current_screen = $current_screen::get($stored_current_screen);
         $current_screen = call_user_func(array($current_screen, 'get', $stored_current_screen));
     }
     $cascade = self::get_entity_ids(self::get_entity_cascade($query));
     return $cascade;
 }
 /**
  * @see Widget_Posts::register_widget_instance_settings_early()
  * @see Widget_Posts::register_widget_settings()
  */
 function test_register_widget_instance_settings_early()
 {
     $wp = new \WP();
     $wp->main();
     foreach ($this->customize_manager->settings() as $setting_id => $setting) {
         if (preg_match('/^widget_/', $setting_id)) {
             $this->assertInstanceOf(__NAMESPACE__ . '\\WP_Customize_Widget_Setting', $setting);
         }
     }
 }
示例#12
0
    $c['Author'] = 'author/';
    $c[$author] = 'author/' . $author;
    WP::printBreadCrumbs($c);
    WP::author($author);
})->where('author', 'alpha_numeric');
Router::get(WP::path() . 'author/{author}/page/{currentPage}', function ($author, $currentPage) {
    $c = array();
    $c['Author'] = 'author/';
    $c[$author] = 'author/' . $author;
    WP::printBreadCrumbs($c);
    Data::get()->set('current-page', $currentPage);
    WP::author($author);
})->where(array('author' => 'alpha_numeric', 'currentPage' => 'integer'));
Router::get(WP::path() . 'tag/', function () {
    $c = array();
    $c['Tag'] = 'tag/';
    WP::printBreadCrumbs($c);
    WP::template('tag-list', '<a class="wp-tag-list" href="{{$path}}tag/{{$slug}}">{{$name}} - {{$count}}</a>');
    $tags = WP::topTags(1000);
    View::html("<div class='clearfix'>{$tags}</div>");
    WP::clearTemplate('tag-list');
});
Router::get(WP::path() . '{slug}', function ($slug) {
    WP::printBreadCrumbs(array(str_replace('-', ' ', $slug) => $slug));
    WP::post($slug);
})->where('slug', 'alpha_numeric');
Router::get(WP::path() . 'page/{currentPage}', function ($currentPage) {
    WP::printBreadCrumbs(array('Page ' . $currentPage => 'page/' . $currentPage));
    Data::get()->set('current-page', $currentPage);
    WP::index();
})->where('currentPage', 'integer');