function wpcampus_2016_enqueue_scripts()
{
    // Load Fonts
    wp_enqueue_style('wpcampus-2016-fonts', 'https://fonts.googleapis.com/css?family=Open+Sans:600,400,300');
    // Add our theme stylesheet
    wp_enqueue_style('wpcampus-2016', get_template_directory_uri() . '/css/styles.css', array('wpcampus-2016-fonts'), filemtime(get_template_directory() . '/css/styles.css'));
    // Add our theme script
    wp_enqueue_script('wpcampus-2016', get_template_directory_uri() . '/js/wpcampus-2016-min.js', array('jquery'), filemtime(get_template_directory() . '/js/wpcampus-2016-min.js'));
    // Add our home styles
    if (is_front_page()) {
        wp_enqueue_style('wpcampus-2016-home', get_template_directory_uri() . '/css/home.css', array('wpcampus-2016'), filemtime(get_template_directory() . '/css/home.css'));
    }
    // Add our iframe script
    if (is_page_template('template-map.php')) {
        wp_enqueue_script('wpcampus-2016-iframe', get_template_directory_uri() . '/js/wpcampus-2016-iframe-min.js', array('jquery'), filemtime(get_template_directory() . '/js/wpcampus-2016-iframe-min.js'));
    }
    // Register handlebars
    wp_register_script('handlebars', '//cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.0.5/handlebars.min.js');
    // Get the API route
    $wp_rest_api_route = function_exists('rest_get_url_prefix') ? rest_get_url_prefix() : '';
    if (!empty($wp_rest_api_route)) {
        $wp_rest_api_route = "/{$wp_rest_api_route}/wp/v2/";
    }
    // For the livestream page
    if (is_page_template('template-livestream.php')) {
        // Enqueue the schedule script
        wp_enqueue_script('wpcampus-2016-livestream', get_template_directory_uri() . '/js/wpcampus-2016-livestream-min.js', array('jquery', 'handlebars'), false, true);
        // Pass some data
        wp_localize_script('wpcampus-2016-livestream', 'wpc_ls', array('wp_api_route' => $wp_rest_api_route));
    }
}
 function angular_scripts()
 {
     wp_enqueue_script('angular_core', get_template_directory_uri() . '/build/js/angular.min.js', array('jquery'), null, false);
     wp_enqueue_script('bootstrap-js', get_template_directory_uri() . '/build/js/bootstrap.js', array('jquery'), null, false);
     wp_enqueue_script('angular_theme', get_template_directory_uri() . '/build/js/scripts.js', array('angular_core'), null, false);
     //wp_enqueue_script( 'angular_theme', get_template_directory_uri().'/assets/js/angular-app.js', array( 'angular_core' ), null, false );
     wp_localize_script('angular_theme', 'ajaxInfo', array('api_url' => rest_get_url_prefix() . '/wp/v2/', 'template_directory' => get_template_directory_uri() . '/', 'nonce' => wp_create_nonce('wp_rest'), 'is_admin' => current_user_can('administrator')));
 }
 function enqueue_scripts()
 {
     wp_enqueue_style('bootstrapCSS', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css', array(), '1.0', 'all');
     wp_enqueue_script('angular-core', 'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js', array('jquery'), '1.0', false);
     wp_enqueue_script('angular-resource', 'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular-resource.js', array('angular-core'), '1.0', false);
     wp_enqueue_script('ui-router', 'https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.2.15/angular-ui-router.min.js', array('angular-core'), '1.0', false);
     wp_enqueue_script('ngScripts', get_template_directory_uri() . '/assets/js/angular-theme.js', array('ui-router'), '1.0', false);
     wp_localize_script('ngScripts', 'appInfo', array('api_url' => rest_get_url_prefix() . '/wp/v2/', 'template_directory' => get_template_directory_uri() . '/', 'nonce' => wp_create_nonce('wp_rest'), 'is_admin' => current_user_can('administrator')));
 }
 /**
  * Check if is request to our REST API.
  *
  * @return bool
  */
 protected function is_request_to_rest_api()
 {
     if (empty($_SERVER['REQUEST_URI'])) {
         return false;
     }
     $rest_prefix = trailingslashit(rest_get_url_prefix());
     // Check if our endpoint.
     $woocommerce = false !== strpos($_SERVER['REQUEST_URI'], $rest_prefix . 'wc/');
     // Allow third party plugins use our authentication methods.
     $third_party = false !== strpos($_SERVER['REQUEST_URI'], $rest_prefix . 'wc-');
     return apply_filters('woocommerce_rest_is_request_to_rest_api', $woocommerce || $third_party);
 }
 function angular_scripts()
 {
     wp_enqueue_script('angular_core', get_template_directory_uri() . '/assets/js/angular.min.js', array('jquery'), null, false);
     wp_enqueue_script('bootstrap-js', get_template_directory_uri() . '/assets/js/bootstrap.js', array('jquery'), null, false);
     wp_enqueue_script('angular_theme', get_template_directory_uri() . '/assets/js/scripts.js', array('angular_core'), null, false);
     // // // app js
     // wp_enqueue_script( 'angular_theme', get_template_directory_uri().'/src/js/app.js', array( 'angular_core' ), null, false );
     // wp_enqueue_script( 'angular_controller', get_template_directory_uri().'/src/js/app.controller.js', array( 'angular_core' ), null, false );
     // wp_enqueue_script( 'angular_service', get_template_directory_uri().'/src/js/app.factory.js', array( 'angular_core' ), null, false );
     // wp_enqueue_script( 'angular_filter', get_template_directory_uri().'/src/js/app.filter.js', array( 'angular_core' ), null, false );
     // wp_enqueue_script( 'angular_directive', get_template_directory_uri().'/src/js/app.directive.js', array( 'angular_core' ), null, false );
     // //other js
     // wp_enqueue_script( 'modernizr-js', get_template_directory_uri().'/src/js/modernizr.js', array( 'angular_core' ), null, false );
     wp_localize_script('angular_theme', 'ajaxInfo', array('api_url' => rest_get_url_prefix() . '/wp/v2/', 'template_directory' => get_template_directory_uri() . '/', 'nonce' => wp_create_nonce('wp_rest'), 'is_admin' => current_user_can('administrator'), 'posts_per_page' => get_option('posts_per_page ')));
 }
/**
 * Check if the current request is to one of the plugin's REST endpoints
 *
 * @param string $type list|run
 *
 * @return bool
 */
function is_rest_endpoint_request($type = 'list')
{
    // Which endpoint are we checking
    $endpoint = null;
    switch ($type) {
        case 'list':
            $endpoint = REST_API::ENDPOINT_LIST;
            break;
        case 'run':
            $endpoint = REST_API::ENDPOINT_RUN;
            break;
    }
    // No endpoint to check
    if (is_null($endpoint)) {
        return false;
    }
    // Build the full endpoint and check against the current request
    $run_endpoint = sprintf('%s/%s/%s', rest_get_url_prefix(), REST_API::API_NAMESPACE, $endpoint);
    return in_array($run_endpoint, parse_request());
}
function get_rest_url($blog_id = null, $path = '/', $scheme = 'rest')
{
    if (empty($path)) {
        $path = '/';
    }
    if (is_multisite() && get_blog_option($blog_id, 'permalink_structure') || get_option('permalink_structure')) {
        $url = get_home_url($blog_id, rest_get_url_prefix(), $scheme);
        $url .= '/' . ltrim($path, '/');
    } else {
        $url = trailingslashit(get_home_url($blog_id, '', $scheme));
        $path = '/' . ltrim($path, '/');
        $url = add_query_arg('rest_route', $path, $url);
    }
    if (is_ssl()) {
        // If the current host is the same as the REST URL host, force the REST URL scheme to HTTPS.
        if ($_SERVER['SERVER_NAME'] === parse_url(get_home_url($blog_id), PHP_URL_HOST)) {
            $url = set_url_scheme($url, 'https');
        }
    }
    return apply_filters('rest_url', $url, $path, $blog_id, $scheme);
}
 function angularScripts()
 {
     // Angular Core
     wp_enqueue_script('angular-core', plugin_dir_url(__FILE__) . 'js/angular.min.js', array('jquery'), null, false);
     wp_enqueue_script('angular-sanitize', plugin_dir_url(__FILE__) . 'js/angular-sanitize.min.js', array('jquery'), null, false);
     wp_enqueue_script('html-janitor', plugin_dir_url(__FILE__) . 'js/html-janitor.js', array('jquery'), null, false);
     wp_enqueue_script('angular-app', plugin_dir_url(__FILE__) . 'js/angular-app.js', array('html-janitor'), null, false);
     // Angular Factories
     wp_enqueue_script('angular-factories', plugin_dir_url(__FILE__) . 'js/angular-factories.js', array('angular-app'), null, false);
     // Angular Directives
     wp_enqueue_script('angular-post-directives', plugin_dir_url(__FILE__) . 'js/angular-posts-directives.js', array('angular-factories'), null, false);
     // Template Directory
     $template_directory = array('list_detail' => plugin_dir_url(__FILE__) . 'angularjs-templates/list-detail.html', 'single_detail' => plugin_dir_url(__FILE__) . 'angularjs-templates/single-detail.html', 'new_post' => plugin_dir_url(__FILE__) . 'angularjs-templates/new-post.html', 'post_content' => plugin_dir_url(__FILE__) . 'angularjs-templates/post-content.html');
     // TEMPLATE OVERRIDES
     if (file_exists(get_stylesheet_directory() . '/angularjs-templates/list-detail.html')) {
         $template_directory['list_detail'] = get_stylesheet_directory_uri() . '/angularjs-templates/list-detail.html';
     }
     if (file_exists(get_stylesheet_directory() . '/angularjs-templates/single-detail.html')) {
         $template_directory['single_detail'] = get_stylesheet_directory_uri() . '/angularjs-templates/single-detail.html';
     }
     if (file_exists(get_stylesheet_directory() . '/angularjs-templates/new-post.html')) {
         $template_directory['new_post'] = get_stylesheet_directory_uri() . '/angularjs-templates/new-post.html';
     }
     if (file_exists(get_stylesheet_directory() . '/angularjs-templates/post-content.html')) {
         $template_directory['post_content'] = get_stylesheet_directory_uri() . '/angularjs-templates/post-content.html';
     }
     $angularjs_for_wp_localize = array('site' => get_bloginfo('wpurl'), 'nonce' => wp_create_nonce('wp_json'), 'template_directory' => $template_directory);
     if (function_exists('json_url')) {
         $angularjs_for_wp_localize['base'] = json_url();
     }
     if (function_exists('rest_get_url_prefix')) {
         $angularjs_for_wp_localize['base'] = get_bloginfo('wpurl') . '/' . rest_get_url_prefix() . '/wp/v2';
     }
     // Localize Variables
     wp_localize_script('angular-core', 'wpAngularVars', $angularjs_for_wp_localize);
 }
 function __social_scripts_enqueue()
 {
     $dev = false;
     if ($dev) {
         wp_enqueue_script('hello-js', API_SOCIAL_URL . '/assets/js/hello.all.js', array('jquery'), API_SOCIAL_LOGIN_VERSION, false);
         wp_enqueue_script('social-js', API_SOCIAL_URL . '/assets/js/social.js', array('hello-js'), API_SOCIAL_LOGIN_VERSION, false);
     } else {
         wp_enqueue_script('hello-js', API_SOCIAL_URL . '/build/js/hello.all.min.js', array('jquery'), API_SOCIAL_LOGIN_VERSION, false);
         wp_enqueue_script('social-js', API_SOCIAL_URL . '/build/js/social.min.js', array('hello-js'), API_SOCIAL_LOGIN_VERSION, false);
     }
     $app_data = array('api_url' => get_bloginfo('wpurl') . '/wp-json');
     if (function_exists('rest_get_url_prefix')) {
         $app_data['api_url'] = get_bloginfo('wpurl') . '/' . rest_get_url_prefix() . '/social_login';
     } elseif (function_exists('json_url')) {
         $app_data['api_url'] = json_url();
     }
     $social_app = $this->__get_social_apps();
     foreach ($social_app as $key => $value) {
         if (!empty($value)) {
             $app_data[$key] = $value;
         }
     }
     wp_localize_script('social-js', 'socialLogin', $app_data);
 }
Beispiel #10
0
/**
 * Get URL to a REST endpoint on a site.
 *
 * @todo Check if this is even necessary
 *
 * @param int    $blog_id Blog ID. Optional. The ID of the multisite blog to get URL for. Default null of null returns URL for current blog.
 * @param string $path    Optional. REST route. Default empty.
 * @param string $scheme  Optional. Sanitization scheme. Default 'json'.
 * @return string Full URL to the endpoint.
 */
function get_rest_url($blog_id = null, $path = '/', $scheme = 'json')
{
    if (empty($path)) {
        $path = '/';
    }
    if (get_option('permalink_structure')) {
        $url = get_home_url($blog_id, rest_get_url_prefix(), $scheme);
        $url .= '/' . ltrim($path, '/');
    } else {
        $url = trailingslashit(get_home_url($blog_id, '', $scheme));
        $path = '/' . ltrim($path, '/');
        $url = add_query_arg('rest_route', $path, $url);
    }
    /**
     * Filter the REST URL.
     *
     * @since 1.0
     *
     * @param string $url     REST URL.
     * @param string $path    REST route.
     * @param int    $blod_ig Blog ID.
     * @param string $scheme  Sanitization scheme.
     */
    return apply_filters('rest_url', $url, $path, $blog_id, $scheme);
}
<?php

use VersionPress\VersionPress;
$apiConfig = ['root' => get_home_url(), 'adminUrl' => get_admin_url(), 'urlPrefix' => rest_get_url_prefix(), 'queryParam' => 'rest_route', 'permalinkStructure' => get_option('permalink_structure'), 'nonce' => wp_create_nonce('wp_rest')];
?>
<script>
    var VP_API_Config = <?php 
echo json_encode($apiConfig);
?>
</script>

<?php 
$vpVersion = VersionPress::getVersion();
wp_enqueue_style('versionpress_gui_style', plugins_url('../public/gui/app.css', __FILE__), [], $vpVersion);
wp_enqueue_script('versionpress_gui_script', plugins_url('../public/gui/app.js', __FILE__), [], $vpVersion);
 /**
  * Enqueue scripts and styles for the preview panel
  *
  * @return null
  * @since 0.1
  */
 public function enqueue_preview_assets()
 {
     // Load core preview styles
     wp_enqueue_style('content-layout-preview', CLC_Content_Layout_Control::$url . '/css/content-layout-preview.css', array('dashicons'), '0.1');
     // Load required control, model and view classes
     wp_enqueue_script('content-layout-preview-js', CLC_Content_Layout_Control::$url . '/js/content-layout-preview.js', array('wp-backbone', 'customize-preview'), '0.1', true);
     // Pass settings to the script
     global $wp_customize;
     wp_localize_script('content-layout-preview-js', 'CLC_Preview_Settings', array('root' => home_url(rest_get_url_prefix()), 'nonce' => wp_create_nonce('wp_rest'), 'previewed_theme' => $wp_customize->get_stylesheet(), 'preview_nonce' => wp_create_nonce('preview-customize_' . $wp_customize->get_stylesheet()), 'i18n' => array('edit_component' => $this->i18n['edit_component'])));
     // Load preview data in `wp_footer` so we have access to template functions like is_page()
     add_action('wp_footer', array($this, 'enqueue_preview_data'));
     // Load component-specific models and views
     foreach (CLC_Content_Layout_Control()->components as $id => $component) {
         $component->enqueue_preview_assets();
     }
 }
Beispiel #13
0
 /**
  * Returns the REST API URL prefix.
  */
 public function getUrlPrefix()
 {
     return rest_get_url_prefix();
 }
Beispiel #14
0
/**
 * Retrieves the URL to a REST endpoint on a site.
 *
 * Note: The returned URL is NOT escaped.
 *
 * @since 4.4.0
 *
 * @todo Check if this is even necessary
 * @global WP_Rewrite $wp_rewrite
 *
 * @param int    $blog_id Optional. Blog ID. Default of null returns URL for current blog.
 * @param string $path    Optional. REST route. Default '/'.
 * @param string $scheme  Optional. Sanitization scheme. Default 'rest'.
 * @return string Full URL to the endpoint.
 */
function get_rest_url($blog_id = null, $path = '/', $scheme = 'rest')
{
    if (empty($path)) {
        $path = '/';
    }
    if (is_multisite() && get_blog_option($blog_id, 'permalink_structure') || get_option('permalink_structure')) {
        global $wp_rewrite;
        if ($wp_rewrite->using_index_permalinks()) {
            $url = get_home_url($blog_id, $wp_rewrite->index . '/' . rest_get_url_prefix(), $scheme);
        } else {
            $url = get_home_url($blog_id, rest_get_url_prefix(), $scheme);
        }
        $url .= '/' . ltrim($path, '/');
    } else {
        $url = trailingslashit(get_home_url($blog_id, '', $scheme));
        $path = '/' . ltrim($path, '/');
        $url = add_query_arg('rest_route', $path, $url);
    }
    if (is_ssl()) {
        // If the current host is the same as the REST URL host, force the REST URL scheme to HTTPS.
        if ($_SERVER['SERVER_NAME'] === parse_url(get_home_url($blog_id), PHP_URL_HOST)) {
            $url = set_url_scheme($url, 'https');
        }
    }
    /**
     * Filters the REST URL.
     *
     * Use this filter to adjust the url returned by the get_rest_url() function.
     *
     * @since 4.4.0
     *
     * @param string $url     REST URL.
     * @param string $path    REST route.
     * @param int    $blog_id Blog ID.
     * @param string $scheme  Sanitization scheme.
     */
    return apply_filters('rest_url', $url, $path, $blog_id, $scheme);
}
Beispiel #15
0
/**
 * Retrieves the URL to a REST endpoint on a site.
 *
 * Note: The returned URL is NOT escaped.
 *
 * @since 4.4.0
 *
 * @todo Check if this is even necessary
 *
 * @param int    $blog_id Optional. Blog ID. Default of null returns URL for current blog.
 * @param string $path    Optional. REST route. Default '/'.
 * @param string $scheme  Optional. Sanitization scheme. Default 'rest'.
 * @return string Full URL to the endpoint.
 */
function get_rest_url($blog_id = null, $path = '/', $scheme = 'rest')
{
    if (empty($path)) {
        $path = '/';
    }
    if (is_multisite() && get_blog_option($blog_id, 'permalink_structure') || get_option('permalink_structure')) {
        $url = get_home_url($blog_id, rest_get_url_prefix(), $scheme);
        $url .= '/' . ltrim($path, '/');
    } else {
        $url = trailingslashit(get_home_url($blog_id, '', $scheme));
        $path = '/' . ltrim($path, '/');
        $url = add_query_arg('rest_route', $path, $url);
    }
    /**
     * Filter the REST URL.
     *
     * Use this filter to adjust the url returned by the `get_rest_url` function.
     *
     * @since 4.4.0
     *
     * @param string $url     REST URL.
     * @param string $path    REST route.
     * @param int    $blog_id Blog ID.
     * @param string $scheme  Sanitization scheme.
     */
    return apply_filters('rest_url', $url, $path, $blog_id, $scheme);
}
 /**
  * Returns an array containing the data to be localized.
  *
  * @return array
  */
 public function get_data()
 {
     $nonce = wp_create_nonce('wp_rest');
     return array('endpoints' => array('domain' => home_url(), 'nonce' => $nonce, 'reset_all' => array('url' => home_url(rest_get_url_prefix() . '/idlikethis/v1/admin/reset-all/')), 'consolidate_all' => array('url' => home_url(rest_get_url_prefix() . '/idlikethis/v1/admin/consolidate-all/'))));
 }
Beispiel #17
0
 function __construct()
 {
     $this->options = ['theme_name' => 'GerminateSPA', 'theme_version' => '0.1', 'theme_uri' => get_template_directory_uri() . '/', 'api_url' => rest_get_url_prefix() . '/wp/v2/', 'nonce' => wp_create_nonce('wp_rest'), 'is_admin' => current_user_can('administrator')];
     add_action('wp_enqueue_scripts', [$this, 'scripts']);
 }
Beispiel #18
0
/**
 * Check if this is a REST API request
 *
 * @since 0.0.9
 *
 * @return bool
 */
function ingot_is_rest_api()
{
    if (isset($GLOBALS['wp']) && !empty($GLOBALS['wp']->query_vars['rest_route'])) {
        return true;
    }
    if (defined('REST_REQUEST') && REST_REQUEST) {
        return true;
    }
    if (isset($_SERVER, $_SERVER['REQUEST_URI']) && false !== strpos($_SERVER['REQUEST_URI'], rest_get_url_prefix())) {
        return true;
    }
}
 /**
  * Returns an array containing the data to be localized.
  *
  * @return array
  */
 public function get_data()
 {
     $nonce = wp_create_nonce('wp_rest');
     return array('endpoints' => array('domain' => home_url(), 'nonce' => $nonce, 'button_click' => array('url' => home_url(rest_get_url_prefix() . '/idlikethis/v1/button-click/'))));
 }
Beispiel #20
0
/**
 * Adds REST rewrite rules.
 *
 * @since 4.4.0
 *
 * @see add_rewrite_rule()
 */
function rest_api_register_rewrites()
{
    add_rewrite_rule('^' . rest_get_url_prefix() . '/?$', 'index.php?rest_route=/', 'top');
    add_rewrite_rule('^' . rest_get_url_prefix() . '/(.*)?', 'index.php?rest_route=/$matches[1]', 'top');
}