function load_scripts() { if (!function_exists('json_get_url_prefix')) { return; } wp_enqueue_style('reactwp_css', asset_path('styles/main.css'), false, null); wp_enqueue_script('jquery'); wp_enqueue_script('reactwp_lib_js', asset_path('scripts/libs.js'), [], null, true); wp_enqueue_script('reactwp_js', asset_path('scripts/main.js'), [], null, true); $settings = array('root' => home_url(json_get_url_prefix()), 'nonce' => wp_create_nonce('wp_json')); wp_localize_script('reactwp_js', 'WP_API_Settings', $settings); }
/** * Enqueue scripts * * @since 0.1 */ public function scripts() { // url for json api $home_url = function_exists('json_get_url_prefix') ? json_get_url_prefix() : false; $settings = array('root' => home_url($home_url), 'nonce' => wp_create_nonce('wp_json')); // wp api client wp_enqueue_script('wp-api-js', WP_LIVE_SEARCH_URL . '/public/assets/js/util--wp-api.js', array('jquery', 'underscore', 'backbone'), WP_LIVE_SEARCH_VERSION, true); wp_localize_script('wp-api-js', 'WP_API_Settings', $settings); // wp search script wp_enqueue_script('wpls-script', WP_LIVE_SEARCH_URL . '/public/assets/js/wp-live-search.js', array('jquery'), WP_LIVE_SEARCH_VERSION, true); wp_localize_script('wpls-script', 'wp_search_vars', array('helperText' => __('one more character', 'wp-live-search'))); }
/** * Plugin Name: WP-API Client JS */ function json_api_client_js() { /** * Check if WP API functionality exists. Not using is_plugin_active in prepartion for */ if (!function_exists('json_get_url_prefix')) { return; } wp_enqueue_script('wp-api-js', plugins_url('build/js/wp-api.js', __FILE__), array('jquery', 'underscore', 'backbone'), '1.0', true); $settings = array('root' => home_url(json_get_url_prefix()), 'nonce' => wp_create_nonce('wp_json')); wp_localize_script('wp-api-js', 'WP_API_Settings', $settings); }
/** * Inject client application scripts. * * This action is called on `wp_enqueue_scripts` and injects required client * application settings from the backend, such as: * * - `root`: Theme root URI. * - `url`: RESTful WP API endpoint prefix. * - `name`: Site name. * - `nonce`: Nonce string. * * @todo Find a way to enqueue JS data without having to register a script URI. */ public function setup() { $site_url = parse_url(site_url()); $routes = array(); if (class_exists('B3_RoutesHelper')) { $routes_helper = new B3_RoutesHelper(); $routes = $routes_helper->get_routes(); } if (current_theme_supports('live-updates')) { wp_enqueue_script('heartbeat'); } $this->require_scripts(); $settings = array('name' => get_bloginfo('name'), 'api' => home_url(json_get_url_prefix()), 'nonce' => wp_create_nonce('wp_json'), 'api_url' => home_url(json_get_url_prefix()), 'site_path' => (string) isset($site_url['path']) ? $site_url['path'] : '', 'root_url' => get_stylesheet_directory_uri(), 'site_url' => site_url(), 'routes' => $routes, 'scripts' => $this->scripts); wp_register_script($this->theme->get_slug() . '-settings', 'settings.js', null, $this->theme->get_version()); wp_localize_script($this->theme->get_slug() . '-settings', 'WP_API_SETTINGS', $settings); wp_enqueue_script($this->theme->get_slug() . '-settings'); }
public function scripts() { if (lasso_user_can('edit_posts')) { wp_enqueue_style('lasso-style', LASSO_URL . '/public/assets/css/lasso.css', LASSO_VERSION, true); wp_enqueue_script('jquery-ui-autocomplete'); wp_enqueue_script('jquery-ui-draggable'); wp_enqueue_script('jquery-ui-sortable'); wp_enqueue_script('jquery-ui-slider'); // media uploader wp_enqueue_media(); // url for json api $home_url = function_exists('json_get_url_prefix') ? json_get_url_prefix() : false; $article_object = lasso_editor_get_option('article_class', 'lasso_editor'); $article_object = empty($article_object) && lasso_get_supported_theme_class() ? lasso_get_supported_theme_class() : $article_object; $featImgClass = lasso_editor_get_option('featimg_class', 'lasso_editor'); $titleClass = lasso_editor_get_option('title_class', 'lasso_editor'); $toolbar_headings = lasso_editor_get_option('toolbar_headings', 'lasso_editor'); $objectsNoSave = lasso_editor_get_option('dont_save', 'lasso_editor'); // post id reference $postid = get_the_ID(); $strings = array('save' => __('Save', 'lasso'), 'saving' => __('Saving...', 'lasso'), 'saved' => __('Saved!', 'lasso'), 'adding' => __('Adding...', 'lasso'), 'added' => __('Added!', 'lasso'), 'loading' => __('Loading...', 'lasso'), 'loadMore' => __('Load More', 'lasso'), 'noPostsFound' => __('No more posts found', 'lasso'), 'galleryCreated' => __('Gallery Created!', 'lasso'), 'galleryUpdated' => __('Gallery Updated!', 'lasso'), 'justWrite' => __('Just write...', 'lasso'), 'chooseImage' => __('Choose an image', 'lasso'), 'updateImage' => __('Update Image', 'lasso'), 'insertImage' => __('Insert Image', 'lasso'), 'selectImage' => __('Select Image', 'lasso'), 'removeFeatImg' => __('Remove featured image?', 'lasso'), 'updateSelectedImg' => __('Update Selected Image', 'lasso'), 'chooseImages' => __('Choose images', 'lasso'), 'editImage' => __('Edit Image', 'lasso'), 'addImages' => __('Add Images', 'lasso'), 'addNewGallery' => __('Add New Gallery', 'lasso'), 'selectGallery' => __('Select Lasso Gallery Image', 'lasso'), 'useSelectedImages' => __('Use Selected Images', 'lasso'), 'publishPost' => __('Publish Post?', 'lasso'), 'publishYes' => __('Yes, publish it!', 'lasso'), 'deletePost' => __('Trash Post?', 'lasso'), 'deleteYes' => __('Yes, trash it!', 'lasso'), 'warning' => __('Oh snap!', 'laso'), 'cancelText' => __('O.K. got it!', 'lasso'), 'missingClass' => __('It looks like we are missing the Article CSS class. Lasso will not function correctly without this CSS class.', 'lasso'), 'missingConfirm' => __('Update Settings', 'lasso'), 'helperText' => __('one more letter', 'lasso'), 'editingBackup' => __('You are currently editing a backup copy of this post.')); $api_url = trailingslashit(home_url()) . 'lasso-internal-api'; $gallery_class = new gallery(); $gallery_nonce_action = $gallery_class->nonce_action; $gallery_nonce = wp_create_nonce($gallery_nonce_action); // localized objects $objects = array('ajaxurl' => esc_url($api_url), 'editor' => 'lasso--content', 'article_object' => $article_object, 'featImgClass' => $featImgClass, 'titleClass' => $titleClass, 'strings' => $strings, 'settingsLink' => function_exists('is_multisite') && is_multisite() ? network_admin_url('settings.php?page=lasso-editor') : admin_url('admin.php?page=lasso-editor-settings'), 'post_status' => get_post_status($postid), 'postid' => $postid, 'permalink' => get_permalink(), 'edit_others_pages' => current_user_can('edit_others_pages') ? 'true' : 'false', 'edit_others_posts' => current_user_can('edit_others_posts') ? 'true' : 'false', 'userCanEdit' => current_user_can('edit_post', $postid), 'can_publish_posts' => current_user_can('publish_posts'), 'can_publish_pages' => current_user_can('publish_pages'), 'author' => is_user_logged_in() ? get_current_user_ID() : false, 'nonce' => wp_create_nonce('lasso_editor'), 'handle' => lasso_editor_settings_toolbar(), 'toolbar' => lasso_editor_text_toolbar(), 'toolbarHeadings' => $toolbar_headings, 'component_modal' => lasso_editor_component_modal(), 'component_sidebar' => lasso_editor_component_sidebar(), 'components' => lasso_editor_components(), 'wpImgEdit' => lasso_editor_wpimg_edit(), 'featImgControls' => lasso_editor_image_controls(), 'featImgNonce' => $gallery_nonce, 'getGallImgNonce' => $gallery_nonce, 'createGallNonce' => $gallery_nonce, 'swapGallNonce' => $gallery_nonce, 'titleNonce' => wp_create_nonce('lasso_update_title'), 'wpImgNonce' => wp_create_nonce('lasso_update_wpimg'), 'deletePost' => wp_create_nonce('lasso_delete_post'), 'searchPosts' => wp_create_nonce('lasso_search_posts'), 'component_options' => lasso_editor_options_blob(), 'newPostModal' => lasso_editor_newpost_modal(), 'allPostModal' => lasso_editor_allpost_modal(), 'mapFormFooter' => lasso_map_form_footer(), 'refreshRequired' => lasso_editor_refresh_message(), 'objectsNoSave' => $objectsNoSave, 'supportedNoSave' => lasso_supported_no_save(), 'postCategories' => lasso_get_objects('category'), 'postTags' => lasso_get_objects('tag'), 'noResultsDiv' => lasso_editor_empty_results(), 'noRevisionsDiv' => lasso_editor_empty_results('revision'), 'mapTileProvider' => function_exists('aesop_map_tile_provider') ? aesop_map_tile_provider($postid) : false, 'mapLocations' => get_post_meta($postid, 'ase_map_component_locations'), 'mapStart' => get_post_meta($postid, 'ase_map_component_start_point', true), 'mapZoom' => get_post_meta($postid, 'ase_map_component_zoom', true), 'revisionModal' => lasso_editor_revision_modal()); // wp api client wp_enqueue_script('wp-api-js', LASSO_URL . '/public/assets/js/source/util--wp-api.js', array('jquery', 'underscore', 'backbone'), LASSO_VERSION, true); $settings = array('root' => home_url($home_url), 'nonce' => wp_create_nonce('wp_json')); wp_localize_script('wp-api-js', 'WP_API_Settings', $settings); $postfix = defined('SCRIPT_DEBUG') && true === SCRIPT_DEBUG ? '' : '.min'; wp_enqueue_script('lasso', LASSO_URL . "/public/assets/js/lasso{$postfix}.js", array('jquery'), LASSO_VERSION, true); wp_localize_script('lasso', 'lasso_editor', apply_filters('lasso_localized_objects', $objects)); } }
/** * Get URL to a JSON endpoint on a site. * * @todo Check if this is even necessary * * @param int $blog_id Blog ID. * @param string $path Optional. JSON route. Default empty. * @param string $scheme Optional. Sanitization scheme. Default 'json'. * @return string Full URL to the endpoint. */ function get_json_url($blog_id = null, $path = '', $scheme = 'json') { if (get_option('permalink_structure')) { $url = get_home_url($blog_id, json_get_url_prefix(), $scheme); if (!empty($path) && is_string($path) && strpos($path, '..') === false) { $url .= '/' . ltrim($path, '/'); } } else { $url = trailingslashit(get_home_url($blog_id, '', $scheme)); if (empty($path)) { $path = '/'; } else { $path = '/' . ltrim($path, '/'); } $url = add_query_arg('json_route', $path, $url); } /** * Filter the JSON URL. * * @since 1.0 * * @param string $url JSON URL. * @param string $path JSON route. * @param int $blod_ig Blog ID. * @param string $scheme Sanitization scheme. */ return apply_filters('json_url', $url, $path, $blog_id, $scheme); }
/** * Get URL to a JSON endpoint on a site * * @todo Check if this is even necessary * @param int $blog_id Blog ID * @param string $path JSON route * @param string $scheme Sanitization scheme (usually 'json') * @return string Full URL to the endpoint */ function get_json_url($blog_id = null, $path = '', $scheme = 'json') { if (get_option('permalink_structure')) { $url = get_home_url($blog_id, json_get_url_prefix(), $scheme); if (!empty($path) && is_string($path) && strpos($path, '..') === false) { $url .= '/' . ltrim($path, '/'); } } else { $url = trailingslashit(get_home_url($blog_id, '', $scheme)); if (empty($path)) { $path = '/'; } else { $path = '/' . ltrim($path, '/'); } $url = add_query_arg('json_route', $path, $url); } return apply_filters('json_url', $url, $path, $blog_id, $scheme); }
/** * Get all uri we don't cache * * @since 2.6 Using json_get_url_prefix() to auto-exclude the WordPress REST API * @since 2.4.1 Auto-exclude WordPress REST API * @since 2.0 * * @return array List of rejected uri */ function get_rocket_cache_reject_uri() { $uri = get_rocket_option('cache_reject_uri', array()); // Exclude cart & checkout pages from e-commerce plugins $uri = array_merge($uri, get_rocket_ecommerce_exclude_pages()); // Exclude hide login plugins $uri = array_merge($uri, get_rocket_logins_exclude_pages()); /** * By default, don't cache the WP REST API. * * @since 2.5.12 * * @param bool false will force to cache the WP REST API */ $rocket_cache_reject_wp_rest_api = apply_filters('rocket_cache_reject_wp_rest_api', true); // Exclude WP REST API if (function_exists('json_get_url_prefix') && $rocket_cache_reject_wp_rest_api) { $uri[] = '/' . json_get_url_prefix() . '/(.*)'; } // Exclude feeds $uri[] = '.*/' . $GLOBALS['wp_rewrite']->feed_base . '/'; /** * Filter the rejected uri * * @since 2.1 * * @param array $uri List of rejected uri */ $uri = apply_filters('rocket_cache_reject_uri', $uri); $uri = implode('|', array_filter($uri)); return $uri; }