/**
  * Prepare a post status object for serialization
  *
  * @param stdClass $status Post status data
  * @param WP_REST_Request $request
  * @return WP_REST_Response Post status data
  */
 public function prepare_item_for_response($status, $request)
 {
     if (false === $status->public && !is_user_logged_in() || true === $status->internal && is_user_logged_in()) {
         return new WP_Error('rest_cannot_read_status', __('Cannot view status.'), array('status' => rest_authorization_required_code()));
     }
     $data = array('name' => $status->label, 'private' => (bool) $status->private, 'protected' => (bool) $status->protected, 'public' => (bool) $status->public, 'queryable' => (bool) $status->publicly_queryable, 'show_in_list' => (bool) $status->show_in_admin_all_list, 'slug' => $status->name);
     $context = !empty($request['context']) ? $request['context'] : 'view';
     $data = $this->add_additional_fields_to_object($data, $request);
     $data = $this->filter_response_by_context($data, $context);
     $response = rest_ensure_response($data);
     $posts_controller = new WP_REST_Posts_Controller('post');
     if ('publish' === $status->name) {
         $response->add_link('archives', rest_url('/wp/v2/' . $posts_controller->get_post_type_base('post')));
     } else {
         $response->add_link('archives', add_query_arg('status', $status->name, rest_url('/wp/v2/' . $posts_controller->get_post_type_base('post'))));
     }
     /**
      * Filter a status returned from the API.
      *
      * Allows modification of the status data right before it is returned.
      *
      * @param WP_REST_Response  $response The response object.
      * @param object            $status   The original status object.
      * @param WP_REST_Request   $request  Request used to generate the response.
      */
     return apply_filters('rest_prepare_status', $response, $status, $request);
 }
/**
 * The plugin bootstrap file
 *
 * This file is read by WordPress to generate the plugin information in the plugin
 * admin area. This file also includes all of the dependencies used by the plugin,
 * registers the activation and deactivation functions, and defines a function
 * that starts the plugin.
 *
 * @link              http://errorstudio.co.uk
 * @since             1.0.0
 *
 * @wordpress-plugin
 * Plugin Name:       Rooftop Content Hierarchy
 * Plugin URI:        http://errorstudio.co.uk
 * Description:       This is a short description of what the plugin does. It's displayed in the WordPress admin area.
 * Version:           1.0.0
 * Author:            Error
 * Author URI:        http://errorstudio.co.uk
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain:       rooftop-content-hierarchy
 * Domain Path:       /languages
 */
function rooftop_add_content_hierarchy($response, $post, $request)
{
    $child_post_args = array('post_parent' => $post->ID, 'post_type' => $post->post_type, 'numberposts' => -1, 'post_status' => array('publish'), 'orderby' => 'menu_order', 'order' => 'ASC');
    if (apply_filters('rooftop_include_drafts', false)) {
        $child_post_args['post_status'][] = 'draft';
    }
    $ancestor_posts = array_map(function ($id) {
        return get_post($id);
    }, get_post_ancestors($post));
    $child_posts = get_children($child_post_args);
    $post_data = function ($p) {
        $post_data = array();
        $post_data['id'] = $p->ID;
        $post_data['title'] = $p->post_title;
        $post_data['type'] = $p->post_type;
        $post_data['slug'] = $p->post_name;
        $post_data['embeddable'] = true;
        return $post_data;
    };
    $post_object = get_post_type_object($post->post_type);
    if ($post_object && property_exists($post_object, 'rest_base')) {
        $rest_base = $post_object->rest_base;
        $rest_url = '/wp/v2/' . $rest_base;
        foreach ($ancestor_posts as $post) {
            $response->add_link('http://docs.rooftopcms.com/link_relations/ancestors', rest_url($rest_url . '/' . $post->ID), $post_data($post));
        }
        foreach ($child_posts as $post) {
            $response->add_link('http://docs.rooftopcms.com/link_relations/children', rest_url($rest_url . '/' . $post->ID), $post_data($post));
        }
    }
    return $response;
}
 public function get_items($request)
 {
     $data = array();
     require_once ABSPATH . '/wp-admin/includes/plugin.php';
     $plugins = get_plugins();
     // Exit early if empty set.
     if (empty($plugins)) {
         return rest_ensure_response($data);
     }
     // Store pagation values for headers.
     $total_plugins = count($plugins);
     $per_page = (int) $request['per_page'];
     if (!empty($request['offset'])) {
         $offset = $request['offset'];
     } else {
         $offset = ($request['page'] - 1) * $per_page;
     }
     $max_pages = ceil($total_plugins / $per_page);
     $page = ceil((int) $offset / $per_page + 1);
     // Find count to display per page.
     if ($page > 1) {
         $length = $total_plugins - $offset;
         if ($length > $per_page) {
             $length = $per_page;
         }
     } else {
         $length = $total_plugins > $per_page ? $per_page : $total_plugins;
     }
     // Split plugins array.
     $plugins = array_slice($plugins, $offset, $length);
     foreach ($plugins as $obj) {
         $plugin = $this->prepare_item_for_response($obj, $request);
         if (is_wp_error($plugin)) {
             continue;
         }
         $data[] = $this->prepare_response_for_collection($plugin);
     }
     $response = rest_ensure_response($data);
     // Add pagination headers to response.
     $response->header('X-WP-Total', (int) $total_plugins);
     $response->header('X-WP-TotalPages', (int) $max_pages);
     // Add pagination link headers to response.
     $base = add_query_arg($request->get_query_params(), rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)));
     if ($page > 1) {
         $prev_page = $page - 1;
         if ($prev_page > $max_pages) {
             $prev_page = $max_pages;
         }
         $prev_link = add_query_arg('page', $prev_page, $base);
         $response->link_header('prev', $prev_link);
     }
     if ($max_pages > $page) {
         $next_page = $page + 1;
         $next_link = add_query_arg('page', $next_page, $base);
         $response->link_header('next', $next_link);
     }
     // Return requested collection.
     return $response;
 }
 /**
  * Test getting all shipping methods.
  *
  * @since 2.7.0
  */
 public function test_get_shipping_methods()
 {
     wp_set_current_user($this->user);
     $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v1/shipping_methods'));
     $methods = $response->get_data();
     $this->assertEquals(200, $response->get_status());
     $this->assertContains(array('id' => 'free_shipping', 'title' => 'Free shipping', 'description' => 'Free shipping is a special method which can be triggered with coupons and minimum spends.', '_links' => array('self' => array(array('href' => rest_url('/wc/v1/shipping_methods/free_shipping'))), 'collection' => array(array('href' => rest_url('/wc/v1/shipping_methods'))))), $methods);
 }
 public function event_ticket_type_links_filter($links, $post)
 {
     $prefix = "rooftop-events/v2";
     $links['self'] = array('href' => rest_url(trailingslashit($prefix) . 'ticket_types/' . $post->ID));
     $links['collection'] = array('href' => rest_url(trailingslashit($prefix) . 'ticket_types'));
     $links['about'] = array('href' => rest_url('/wp/v2/types/' . $this->post_type));
     return $links;
 }
 /**
  * Test getting all payment gateways.
  *
  * @since 2.7.0
  */
 public function test_get_payment_gateways()
 {
     wp_set_current_user($this->user);
     $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v1/payment_gateways'));
     $gateways = $response->get_data();
     $this->assertEquals(200, $response->get_status());
     $this->assertContains(array('id' => 'cheque', 'title' => 'Check Payments', 'description' => 'Please send a check to Store Name, Store Street, Store Town, Store State / County, Store Postcode.', 'order' => '', 'enabled' => true, 'method_title' => 'Check Payments', 'method_description' => "Allows check payments. Why would you take checks in this day and age? Well you probably wouldn't but it does allow you to make test purchases for testing order emails and the 'success' pages etc.", 'settings' => $this->get_settings('WC_Gateway_Cheque'), '_links' => array('self' => array(array('href' => rest_url('/wc/v1/payment_gateways/cheque'))), 'collection' => array(array('href' => rest_url('/wc/v1/payment_gateways'))))), $gateways);
 }
Example #7
0
 /**
  * Test if the site was added as an oEmbed provider.
  */
 function test_add_oembed_provider()
 {
     $oembed = _wp_oembed_get_object();
     wp_oembed_remove_provider(home_url('/*'));
     $this->assertArrayNotHasKey(home_url('/*'), $oembed->providers);
     $this->plugin()->add_oembed_provider();
     $this->assertArrayHasKey(home_url('/*'), $oembed->providers);
     $this->assertEquals(array(esc_url(rest_url('wp/v2/oembed')), false), $oembed->providers[home_url('/*')]);
 }
Example #8
0
/**
 * Enqueue scripts and styles.
 */
function qod_scripts()
{
    wp_enqueue_script('jquery');
    wp_enqueue_style('qod-style', get_stylesheet_uri());
    wp_enqueue_style('font-awesome-cdn', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css', array(), '4.4.0');
    wp_enqueue_script('qod-skip-link-focus-fix', get_template_directory_uri() . '/build/js/skip-link-focus-fix.min.js', array(), '20130115', true);
    wp_enqueue_script('qod-api', get_template_directory_uri() . '/build/js/api.min.js', array('jquery'), false, true);
    wp_localize_script('qod-api', 'api_vars', array('root_url' => esc_url_raw(rest_url()), 'home_url' => esc_url_raw(home_url()), 'nonce' => wp_create_nonce('wp_rest'), 'success' => 'Thanks, your quote submission was received.', 'failure' => 'Your submission could not be processed.'));
}
Example #9
0
 public function load_flashcards_scripts()
 {
     wp_enqueue_script('front-end', get_template_directory_uri() . '/js/ui.js', array('jquery'), '.1', true);
     wp_enqueue_script('app', get_template_directory_uri() . '/js/app.js', array('jquery', 'underscore'), '.1', true);
     wp_enqueue_style('main-theme-styles', get_stylesheet_uri());
     $theme_settings = (array) get_option('flashcard_settings');
     $theme_verify_app = base64_encode($theme_settings['username'] . ':' . $theme_settings['app_key']);
     wp_localize_script('app', 'wpInfo', array('api_url' => rest_url() . 'wp/v2/posts', 'template_directory' => get_template_directory_uri() . '/', 'nonce' => wp_create_nonce('wp_rest'), 'app_permission' => $theme_verify_app));
 }
Example #10
0
function building_url()
{
    $categories = get_the_category();
    $cats = array();
    foreach ($categories as $c) {
        $cats[] = $c->term_id;
    }
    $url = add_query_arg(array('filter[cat]' => implode(",", $cats), 'filter[posts_per_page]' => 5), rest_url('wp/v2/posts'));
    return $url;
}
Example #11
0
/**
 * Enqueue scripts and styles.
 */
function qod_scripts()
{
    wp_enqueue_style('qod-style', get_stylesheet_uri());
    wp_enqueue_style('font-awesome-cdn', 'https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css', array(), '4.4.0');
    wp_enqueue_script('qod-skip-link-focus-fix', get_template_directory_uri() . '/build/js/skip-link-focus-fix.min.js', array(), '20130115', true);
    // Add API-related scripts here...
    wp_enqueue_script('angular', get_template_directory_uri() . '/build/js/angular/angular.min.js', array(), false, true);
    wp_enqueue_script('quotesdev-api', get_template_directory_uri() . '/build/js/api.min.js', array('angular'), false, true);
    wp_localize_script('quotesdev-api', 'api_vars', array('root_url' => esc_url_raw(rest_url()), 'home_url' => esc_url_raw(home_url()), 'nonce' => wp_create_nonce('wp_rest'), 'success' => 'Submitted...Thanks', 'failure' => 'Not submitted...Try again'));
}
Example #12
0
/**
*
* Enqueue scripts and styles.
*
*/
function sourgems_scripts()
{
    // Load our main stylesheet.
    wp_enqueue_style('style', get_stylesheet_uri());
    wp_enqueue_script('jquery');
    wp_register_script('sourgems-script', get_template_directory_uri() . '/app.js', array(), '20150910', true);
    wp_enqueue_script('sourgems-script');
    //localize data for script
    wp_localize_script('sourgems-script', 'AUTH', array('root' => esc_url_raw(rest_url()), 'nonce' => wp_create_nonce('wp_rest'), 'current_user_id' => get_current_user_id()));
}
Example #13
0
 /**
  * Get URL for Ingot API or an API route
  *
  * Note URL is returned unescaped. Don't forget to late escape.
  *
  * @since 0.2.0
  *
  * @param null|string $route Optional. If null base URL is returned. Optionally provide a route name.
  *
  * @return string
  */
 public static function get_url($route = null)
 {
     if ($route) {
         $route = self::get_route($route);
     } else {
         $route = self::get_namespace();
     }
     $url = trailingslashit(rest_url($route));
     return $url;
 }
Example #14
0
/**
 * Load Scripts
 *
 * Enqueues the required scripts.
 *
 * @since	1.3
 * @global	$post
 * @return	void
 */
function mdjm_load_scripts()
{
    $js_dir = MDJM_PLUGIN_URL . '/assets/js/';
    wp_register_script('mdjm-ajax', $js_dir . 'mdjm-ajax.js', array('jquery'), MDJM_VERSION_NUM);
    wp_enqueue_script('mdjm-ajax');
    wp_localize_script('mdjm-ajax', 'mdjm_vars', apply_filters('mdjm_script_vars', array('ajaxurl' => mdjm_get_ajax_url(), 'rest_url' => esc_url_raw(rest_url('mdjm/v1/')), 'ajax_loader' => MDJM_PLUGIN_URL . '/assets/images/loading.gif', 'required_date_message' => __('Please select a date', 'mobile-dj-manager'), 'availability_ajax' => mdjm_get_option('avail_ajax', false), 'available_redirect' => mdjm_get_option('availability_check_pass_page', 'text') != 'text' ? mdjm_get_formatted_url(mdjm_get_option('availability_check_pass_page')) : 'text', 'available_text' => mdjm_get_option('availability_check_pass_text', false), 'unavailable_redirect' => mdjm_get_option('availability_check_fail_page', 'text'), 'unavailable_text' => mdjm_get_option('availability_check_fail_text', false), 'is_payment' => mdjm_is_payment() ? '1' : '0', 'default_gateway' => mdjm_get_default_gateway(), 'payment_loading' => __('Please Wait...', 'mobile-dj-manager'), 'no_payment_amount' => __('Select Payment Amount', 'mobile-dj-manager'), 'no_card_name' => __('Enter the name printed on your card', 'mobile-dj-manager'), 'complete_payment' => mdjm_get_payment_button_text())));
    wp_register_script('jquery-validation-plugin', '//ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js', array('jquery'));
    wp_enqueue_script('jquery-validation-plugin');
    wp_enqueue_script('jquery-ui-datepicker', array('jquery'));
}
 public function event_price_list_links_filter($links, $post)
 {
     $prefix = "rooftop-events/v2";
     $base = "{$prefix}/price_lists";
     $links['prices'] = array('href' => rest_url(trailingslashit($base) . $post->ID . '/prices'), 'embeddable' => true);
     $links['self'] = array('href' => rest_url(trailingslashit($base) . $post->ID));
     $links['collection'] = array('href' => rest_url($base));
     $links['about'] = array('href' => rest_url('/wp/v2/types/' . $this->post_type));
     return $links;
 }
Example #16
0
 /**
  * Add oEmbed discovery links in the website <head>.
  */
 public function add_oembed_discovery_links()
 {
     $output = '';
     if (is_singular()) {
         $output .= '<link rel="alternate" type="application/json+oembed" href="' . esc_url(rest_url('wp/v2/oembed?url=' . get_permalink())) . '" />' . "\n";
         $output .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url(rest_url('wp/v2/oembed?url=' . get_permalink() . '&format=xml')) . '" />' . "\n";
     }
     $output = apply_filters('rest_oembed_discovery_links', $output);
     echo $output;
 }
Example #17
0
function theme_scripts()
{
    wp_register_style('defaultStyles', get_stylesheet_directory_uri() . '/style.css');
    wp_enqueue_style('my-style', get_stylesheet_directory_uri() . '/style.css', array('defaultStyles'));
    // Register any nessesary scripts
    wp_register_script('angularjs', get_stylesheet_directory_uri() . '/node_modules/angular/angular.min.js');
    wp_register_script('angularjs-route', get_stylesheet_directory_uri() . '/node_modules/angular-route/angular-route.min.js');
    wp_register_script('angularjs-inview', get_stylesheet_directory_uri() . '/node_modules/angular-inview/angular-inview.js');
    wp_enqueue_script('my-scripts', get_stylesheet_directory_uri() . '/app/scripts.js', array('angularjs', 'angularjs-route', 'angularjs-inview'));
    wp_localize_script('my-scripts', 'myLocalized', array('app' => trailingslashit(get_template_directory_uri()) . 'app/', 'api_url' => esc_url_raw(rest_url()), 'api_nonce' => wp_create_nonce('wp_rest')));
}
 public function event_links_filter($links, $post)
 {
     $prefix = "rooftop-events/v2";
     $base = "{$prefix}/{$post->post_type}s";
     $links['instances'] = array('href' => rest_url($base . '/' . $post->ID . '/instances'), 'embeddable' => true, 'args' => array('per_page' => 1, 'posts_per_page' => 1));
     $links['related_events'] = array('href' => rest_url($base . '/' . $post->ID . '/related_events'), 'embeddable' => true);
     $links['self'] = array('href' => rest_url(trailingslashit($base) . $post->ID));
     $links['collection'] = array('href' => rest_url($base));
     $links['about'] = array('href' => rest_url('/wp/v2/types/' . $this->post_type));
     return $links;
 }
Example #19
0
 /**
  * Test getting coupons.
  * @since 2.7.0
  */
 public function test_get_coupons()
 {
     wp_set_current_user($this->user);
     $coupon_1 = WC_Helper_Coupon::create_coupon('dummycoupon-1');
     $post_1 = get_post($coupon_1->get_id());
     $coupon_2 = WC_Helper_Coupon::create_coupon('dummycoupon-2');
     $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v1/coupons'));
     $coupons = $response->get_data();
     $this->assertEquals(200, $response->get_status());
     $this->assertEquals(2, count($coupons));
     $this->assertContains(array('id' => $coupon_1->get_id(), 'code' => 'dummycoupon-1', 'amount' => '1.00', 'date_created' => wc_rest_prepare_date_response($post_1->post_date_gmt), 'date_modified' => wc_rest_prepare_date_response($post_1->post_modified_gmt), 'discount_type' => 'fixed_cart', 'description' => 'This is a dummy coupon', 'expiry_date' => '', 'usage_count' => 0, 'individual_use' => false, 'product_ids' => array(), 'exclude_product_ids' => array(), 'usage_limit' => '', 'usage_limit_per_user' => '', 'limit_usage_to_x_items' => 0, 'free_shipping' => false, 'product_categories' => array(), 'excluded_product_categories' => array(), 'exclude_sale_items' => false, 'minimum_amount' => '0.00', 'maximum_amount' => '0.00', 'email_restrictions' => array(), 'used_by' => array(), '_links' => array('self' => array(array('href' => rest_url('/wc/v1/coupons/' . $coupon_1->get_id()))), 'collection' => array(array('href' => rest_url('/wc/v1/coupons'))))), $coupons);
 }
Example #20
0
 /**
  * Test output of add_oembed_discovery_links.
  */
 function test_add_oembed_discovery_links()
 {
     $post_id = $this->factory->post->create();
     $this->go_to(get_permalink($post_id));
     $this->assertQueryTrue('is_single', 'is_singular');
     ob_start();
     $this->class->add_oembed_discovery_links();
     $actual = ob_get_clean();
     $expected = '<link rel="alternate" type="application/json+oembed" href="' . esc_url(rest_url('wp/v2/oembed?url=' . get_permalink($post_id))) . '" />' . "\n";
     $expected .= '<link rel="alternate" type="text/xml+oembed" href="' . esc_url(rest_url('wp/v2/oembed?url=' . get_permalink() . '&format=xml')) . '" />' . "\n";
     $this->assertEquals($expected, $actual);
 }
Example #21
0
 function __react_ang_scripts()
 {
     wp_enqueue_script('react_ang_main', get_template_directory_uri() . '/build/js/react_angular.min.js', array('jquery'), null, true);
     wp_localize_script('react_ang_main', 'ajaxInfo', array('json_url' => esc_url_raw(trailingslashit(rest_url())), 'nonce' => wp_create_nonce('wp_rest'), 'template_directory' => get_template_directory_uri(), 'site_url' => get_bloginfo('wpurl')));
     wp_enqueue_script('react_app', get_template_directory_uri() . '/build/js/react_app_js.js', array('jquery', 'react_ang_main'), null, true);
     wp_localize_script('react_app', 'ajax_data', array('ajax_url' => admin_url('admin-ajax.php'), 'preloader_gif' => admin_url('images/wpspin_light.gif')));
     wp_enqueue_script('bootstrap', get_template_directory_uri() . '/build/js/bootstrap.js', array('jquery'), null, true);
     wp_enqueue_script('scripts', get_template_directory_uri() . '/build/js/scripts.js', array('react_app', 'bootstrap'), null, true);
     wp_enqueue_script('nav-menu', get_template_directory_uri() . '/build/js/nav-menu-script.min.js', array('scripts'), null, true);
     // enqueue main styles
     wp_enqueue_style('styles', get_template_directory_uri() . '/build/css/styles.css', array(), null, 'all');
 }
 public function event_price_links_filter($links, $post)
 {
     $prefix = "rooftop-events/v2";
     $price_list_id = get_post_meta($post->ID, 'price_list_id', true);
     $links['ticket_type'] = array('href' => rest_url(trailingslashit($prefix) . 'ticket_types?parent=' . $post->ID), 'embeddable' => true);
     $links['price_band'] = array('href' => rest_url(trailingslashit($prefix) . 'price_bands?parent=' . $post->ID), 'embeddable' => true);
     $links['price_list'] = array('href' => rest_url(trailingslashit($prefix) . 'price_lists/' . $price_list_id), 'embeddable' => true);
     $links['self'] = array('href' => rest_url(trailingslashit($prefix) . 'price_lists/' . trailingslashit($price_list_id) . 'prices/' . $post->ID));
     $links['collection'] = array('href' => rest_url(trailingslashit($prefix) . 'price_lists/' . trailingslashit($price_list_id) . 'prices'));
     $links['about'] = array('href' => rest_url('/wp/v2/types/' . $this->post_type));
     return $links;
 }
 public function event_instance_links_filter($links, $post)
 {
     $event_id = get_post_meta($post->ID, 'event_id', true);
     $prefix = "rooftop-events/v2";
     $base = "{$prefix}/events/{$event_id}/instances";
     $links['price_list'] = array('href' => rest_url('rooftop-events/v2/' . 'price_lists?type=instance&parent=' . $post->ID), 'embeddable' => true);
     $links['event'] = array('href' => rest_url('rooftop-events/v2/' . 'events/' . $event_id));
     $links['self'] = array('href' => rest_url(trailingslashit($base) . $post->ID));
     $links['collection'] = array('href' => rest_url($base));
     $links['about'] = array('href' => rest_url('/wp/v2/types/' . $this->post_type));
     return $links;
 }
 /**
  * Register all scripts for custom admin pages
  * @param string $slug The current page slug
  */
 function enqueue_admin_scripts($slug)
 {
     $base = get_stylesheet_directory_uri() . '/';
     if ($slug === 'rules_page_terraarcana_zodiac') {
         wp_register_script('bootstrap-min', 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha/js/bootstrap.min.js', array('jquery'));
         wp_enqueue_script('zodiac-admin', $base . 'dist/admin/zodiac/zodiac.js', array('bootstrap-min'), null, true);
         wp_enqueue_style('bootstrap', 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css');
         wp_enqueue_style('bootstrap-theme', 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap-theme.min.css', array('bootstrap'));
         wp_enqueue_style('zodiac-admin', $base . 'dist/admin/zodiac/style.css');
         wp_localize_script('zodiac-admin', 'WP_API_Settings', array('root' => esc_url_raw(rest_url()), 'nonce' => wp_create_nonce('wp_rest')));
     }
 }
 /**
  * Enqueue all public app scripts
  */
 public function enqueue_scripts()
 {
     $base = get_stylesheet_directory_uri() . '/';
     if (isset($_GET['debug'])) {
         wp_register_script('bootstrap', 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.js', array('jquery'));
         wp_enqueue_script('app', $base . 'dist/app.js', array('bootstrap'), null, true);
     } else {
         wp_register_script('bootstrap-min', 'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js', array('jquery'));
         // FIXME: Enqueue minified scripts in production
         wp_enqueue_script('app', $base . 'dist/app.js', array('bootstrap-min'), null, true);
     }
     wp_localize_script('app', 'WP_Theme_Settings', array('imageRoot' => get_template_directory_uri() . '/dist/images/', 'logoutURL' => wp_logout_url(home_url())));
     wp_localize_script('app', 'WP_API_Settings', array('root' => esc_url_raw(rest_url()), 'nonce' => wp_create_nonce('wp_rest')));
 }
 /**
  * Test getting all product reviews.
  *
  * @since 2.7.0
  */
 public function test_get_product_reviews()
 {
     wp_set_current_user($this->user);
     $product = WC_Helper_Product::create_simple_product();
     // Create 10 products reviews for the product
     for ($i = 0; $i < 10; $i++) {
         $review_id = WC_Helper_Product::create_product_review($product->get_id());
     }
     $response = $this->server->dispatch(new WP_REST_Request('GET', '/wc/v1/products/' . $product->get_id() . '/reviews'));
     $product_reviews = $response->get_data();
     $this->assertEquals(200, $response->get_status());
     $this->assertEquals(10, count($product_reviews));
     $this->assertContains(array('id' => $review_id, 'date_created' => '2016-01-01T11:11:11', 'review' => 'Review content here', 'rating' => 0, 'name' => 'admin', 'email' => '*****@*****.**', 'verified' => false, '_links' => array('self' => array(array('href' => rest_url('/wc/v1/products/' . $product->get_id() . '/reviews/' . $review_id))), 'collection' => array(array('href' => rest_url('/wc/v1/products/' . $product->get_id() . '/reviews'))), 'up' => array(array('href' => rest_url('/wc/v1/products/' . $product->get_id()))))), $product_reviews);
 }
Example #27
0
 function wpApp_baseScripts()
 {
     // The App Script
     wp_enqueue_script('wpApp', get_stylesheet_directory_uri() . '/assets/js/wp-app/wp-app.js', array('AngularCore'), null, true);
     //wp_localize_script( 'wpApp', 'APIdata', array( 'api_url' => esc_url_raw( get_json_url() ), 'api_nonce' => wp_create_nonce( 'wp_json' ), 'templateUrl' => get_bloginfo( 'template_directory' ) ) );
     wp_localize_script('wpApp', 'APIdata', array('api_url' => esc_url_raw(rest_url()), 'api_nonce' => wp_create_nonce('wp_rest'), 'templateUrl' => get_bloginfo('template_directory')));
     // Misc Scripts
     wp_enqueue_script('wpAppScripts', get_stylesheet_directory_uri() . '/assets/js/wp-app/wp-app-scripts.js', array('jquery'), null, true);
     // Routes
     wp_enqueue_script('wpAppRoutes', get_stylesheet_directory_uri() . '/assets/js/wp-app/wp-app-routes.js', array('wpApp'), null, true);
     // Factories
     wp_enqueue_script('wpAppFactories', get_stylesheet_directory_uri() . '/assets/js/wp-app/wp-app-factories.js', array('wpApp'), null, true);
     // Controllers
     wp_enqueue_script('wpAppSignup', get_stylesheet_directory_uri() . '/assets/js/wp-app/controllers/wp-app-signup.js', array('wpAppFactories'), null, true);
     wp_enqueue_script('wpAppStyleGuide', get_stylesheet_directory_uri() . '/assets/js/wp-app/controllers/wp-app-sg.js', array('wpAppFactories'), null, true);
 }
/**
 * Create REST API url
 * - Get the current categories
 * - Get the category IDs
 * - Create the arguments for categories and posts-per-page
 * - Create the url
 */
function moreposts_get_json_query()
{
    // get all the categories in the current post
    $cats = get_the_category();
    // make an array of the categories
    $cat_ids = array();
    // loop through each of the categories and grab just the ID
    foreach ($cats as $cat) {
        $cat_ids[] = $cat->term_id;
    }
    // set up the query variable for category IDs and posts per page
    $args = array('filter[cat]' => implode(",", $cat_ids), 'filter[posts_per_page]' => 5);
    // put everything together in a URL
    $url = add_query_arg($args, rest_url('wp/v2/posts'));
    return $url;
}
Example #29
0
    /**
     * Adds JS to footer which enables the autocomplete
     * @since  0.1.0
     */
    public static function footer_js()
    {
        wp_localize_script('jquery-ui-autocomplete', 'cmb2_term_select_field', array('field_ids' => self::$script_data, 'ajax_url' => rest_url(self::REST_BASE)));
        ?>
		<style type="text/css" media="screen">
			.ui-autocomplete.ui-front {
				/* Make jQuery UI autocomplete results visible above UI dialog */
				z-index: 100493 !important;
			}
		</style>
		<script type="text/javascript">
			<?php 
        include_once 'script.js';
        ?>
		</script>
		<?php 
    }
Example #30
-1
 /**
  * Test getting customers.
  *
  * @since 2.7.0
  */
 public function test_get_customers()
 {
     wp_set_current_user(1);
     $customer_1 = WC_Helper_Customer::create_customer();
     WC_Helper_Customer::create_customer('test2', 'test2', '*****@*****.**');
     $request = new WP_REST_Request('GET', '/wc/v1/customers');
     $request->set_query_params(array('orderby' => 'id'));
     $response = $this->server->dispatch($request);
     $customers = $response->get_data();
     $this->assertEquals(200, $response->get_status());
     $this->assertEquals(2, count($customers));
     $this->assertContains(array('id' => $customer_1->get_id(), 'date_created' => wc_rest_prepare_date_response(date('Y-m-d H:i:s', $customer_1->get_date_created())), 'date_modified' => wc_rest_prepare_date_response(date('Y-m-d H:i:s', $customer_1->get_date_modified())), 'email' => '*****@*****.**', 'first_name' => 'Justin', 'last_name' => '', 'role' => 'customer', 'username' => 'testcustomer', 'billing' => array('first_name' => '', 'last_name' => '', 'company' => '', 'address_1' => '123 South Street', 'address_2' => 'Apt 1', 'city' => 'Philadelphia', 'state' => 'PA', 'postcode' => '19123', 'country' => 'US', 'email' => '', 'phone' => ''), 'shipping' => array('first_name' => '', 'last_name' => '', 'company' => '', 'address_1' => '123 South Street', 'address_2' => 'Apt 1', 'city' => 'Philadelphia', 'state' => 'PA', 'postcode' => '19123', 'country' => 'US'), 'is_paying_customer' => false, 'orders_count' => 0, 'total_spent' => '0.00', 'avatar_url' => $customer_1->get_avatar_url(), 'meta_data' => array(), '_links' => array('self' => array(array('href' => rest_url('/wc/v1/customers/' . $customer_1->get_id() . ''))), 'collection' => array(array('href' => rest_url('/wc/v1/customers'))))), $customers);
 }