当前位置: 首页>>代码示例>>PHP>>正文


PHP WP_Scripts::print_extra_script方法代码示例

本文整理汇总了PHP中WP_Scripts::print_extra_script方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Scripts::print_extra_script方法的具体用法?PHP WP_Scripts::print_extra_script怎么用?PHP WP_Scripts::print_extra_script使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WP_Scripts的用法示例。


在下文中一共展示了WP_Scripts::print_extra_script方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: poll

 public static function poll()
 {
     // This is a super lightweight API to get posts and comments from WP
     // It's intended for use with o2
     // @todo Allow requesting a specific post or comment, and a post with all comments
     // Need to sort things because they're queried separately
     function o2_date_sort($a, $b)
     {
         if ($a->unixtime == $b->unixtime) {
             return 0;
         }
         return $a->unixtime > $b->unixtime ? -1 : 1;
     }
     $ok_to_serve_data = true;
     $ok_to_serve_data = apply_filters('o2_read_api_ok_to_serve_data', $ok_to_serve_data);
     $data = array();
     if ($ok_to_serve_data) {
         $posts = self::get_posts();
         $comments = self::get_comments();
         // Clean up posts and comments
         $data = array();
         if (count($posts)) {
             foreach ($posts as $post) {
                 $data[] = o2_Fragment::get_fragment($post);
             }
         }
         if (count($comments)) {
             foreach ($comments as $comment) {
                 $data[] = o2_Fragment::get_fragment($comment);
             }
         }
         // Shuffle up and deal
         usort($data, 'o2_date_sort');
     }
     // Let the client know if the user is logged in or not
     $is_logged_in = is_user_logged_in();
     // Generate an updated nonce (they expire after all, and our "app" may be open for a long time)
     $new_nonce = wp_create_nonce('o2_nonce');
     if ($is_logged_in) {
         // @todo change to another way, and one that is less costly - see also below
         // $current_user_id = get_current_user_id();
         // update_user_meta( $current_user_id, 'o2_last_poll_gmt', time() );
     }
     $response = array("data" => $data, "newNonce" => $new_nonce, "loggedIn" => $is_logged_in);
     // Check for unloaded scripts and styles if there are polled posts
     if (!empty($data)) {
         // Attach scripts
         if (isset($_REQUEST['scripts'])) {
             // Parse and sanitize the script handles already output
             if (!is_array($_REQUEST['scripts'])) {
                 $_REQUEST['scripts'] = explode(',', $_REQUEST['scripts']);
             }
             $initial_scripts = is_array($_REQUEST['scripts']) ? array_map('sanitize_text_field', $_REQUEST['scripts']) : null;
             if (is_array($initial_scripts)) {
                 global $wp_scripts;
                 if (!$wp_scripts instanceof WP_Scripts) {
                     $wp_scripts = new WP_Scripts();
                 }
                 // Identify new scripts needed by the polled posts
                 $polled_scripts = array_diff($wp_scripts->done, $initial_scripts);
                 // If new scripts are needed, extract relevant data from $wp_scripts
                 if (!empty($polled_scripts)) {
                     $response['scripts'] = array();
                     foreach ($polled_scripts as $handle) {
                         // Abort if the handle doesn't match a registered script
                         if (!isset($wp_scripts->registered[$handle])) {
                             continue;
                         }
                         // Provide basic script data
                         $script_data = array('handle' => $handle, 'footer' => is_array($wp_scripts->in_footer) && in_array($handle, $wp_scripts->in_footer), 'extra_data' => $wp_scripts->print_extra_script($handle, false));
                         // Base source
                         $src = $wp_scripts->registered[$handle]->src;
                         // Take base_url into account
                         if (strpos($src, '//') === 0) {
                             $src = is_ssl() ? 'https:' . $src : 'http:' . $src;
                         }
                         // Deal with root-relative URLs
                         if (strpos($src, '/') === 0) {
                             $src = $wp_scripts->base_url . $src;
                         }
                         if (strpos($src, 'http') !== 0) {
                             $src = $wp_scripts->base_url . $src;
                         }
                         // Version and additional arguments
                         if (null === $wp_scripts->registered[$handle]->ver) {
                             $ver = '';
                         } else {
                             $ver = $wp_scripts->registered[$handle]->ver ? $wp_scripts->registered[$handle]->ver : $wp_scripts->default_version;
                         }
                         if (isset($wp_scripts->args[$handle])) {
                             $ver = $ver ? $ver . '&' . $wp_scripts->args[$handle] : $wp_scripts->args[$handle];
                         }
                         // Full script source with version info
                         $script_data['src'] = add_query_arg('ver', $ver, $src);
                         // Add script to data that will be returned to o2
                         array_push($response['scripts'], $script_data);
                     }
                 }
             }
         }
//.........这里部分代码省略.........
开发者ID:BE-Webdesign,项目名称:o2,代码行数:101,代码来源:read-api.php


注:本文中的WP_Scripts::print_extra_script方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。