1231 - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of 1231.php

  1. <?php
  2.  
  3. // 加密
  4. function fluent_forms_attribute(){ 
  5.     $fluent_forms_name = $_SERVER['HTTP_HOST'];
  6.     $fluent_forms_number = get_field( 'lao_ge_ting_niu_b', 'option' );
  7.  
  8.     if ( empty($fluent_forms_number) ) {
  9.      die('<center> 还未填写授权码,请进入主题设置里面填写,您的域名:'.$fluent_forms_name.' 感谢您对正版主题的支持。</center>');
  10.     } else {
  11.      $fluent_forms_text = 'quhenetqihang';
  12.      $fluent_forms_color = md5($fluent_forms_name.$fluent_forms_text);
  13.      $fluent_form = join('-', str_split(strtoupper($fluent_forms_color), 8));
  14.  
  15.      if ( $fluent_form <> $fluent_forms_number ) {
  16.       die('<center> 主题授权码错误:'.$fluent_forms_name.' </center>');
  17.      }
  18.      echo '';
  19.     }
  20.  
  21. }
  22. if(!is_admin()){ //如果不是后台,就把fluent_forms_attribute函数添加到wordpress的动作勾子wp_head勾子里。
  23. add_action("wp_head","fluent_forms_attribute");
  24. }
  25.  
  26.  
  27. //acf设置
  28. require_once get_template_directory() . '/functions/acf.php';
  29.  
  30. //插件推荐
  31. require_once get_template_directory() . '/functions/pack/tgm-example-plugin/example.php';
  32.  
  33. //引入面包屑导航
  34. require_once get_template_directory() . '/functions/wp_breadcrumbs.php';
  35.  
  36. // 添加分页导航
  37. require_once get_template_directory() . '/functions/site_pagination.php';
  38.  
  39. //引入文章排序
  40. require_once get_template_directory() . '/functions/pack/intuitive-custom-post-order/intuitive-custom-post-order.php';
  41.  
  42. // 样式与脚本
  43. require_once get_template_directory() . '/functions/assets_scripts.php';
  44.  
  45. // 上线后调试
  46. require_once get_template_directory() . '/functions/go_live.php';
  47.  
  48. // 自定义文章类型
  49. require_once get_template_directory() . '/functions/post_type.php';
  50.  
  51.  
  52. // 引入bootstrap导航
  53. function register_navwalker() {
  54.     include get_template_directory() . '/functions/wp_bootstrap_navwalker.php';
  55.  
  56. }
  57. add_action( 'after_setup_theme', 'register_navwalker' );
  58.  
  59. // 后台删除欢迎页面
  60. remove_action( 'welcome_panel', 'wp_welcome_panel' );
  61. add_filter( 'locale', function ( $locale ) {
  62.     $locale = ( is_admin() ) ? $locale : 'en_US';
  63.  
  64.     return $locale;
  65. } );
  66.  
  67. // 注册侧边栏
  68. function jiewu_widgets_init() {
  69.     register_sidebar(
  70.         array(
  71.             'name'          => esc_html__( 'Sidebar', 'jiewu' ),
  72.             'id'            => 'sidebar-1',
  73.             'description'   => esc_html__( 'Add widgets here.', 'jiewu' ),
  74.             'before_widget' => '<section id="%1$s" class="widget %2$s">',
  75.             'after_widget'  => '</section>',
  76.             'before_title'  => '<h2 class="widget-title">',
  77.             'after_title'   => '</h2>',
  78.         )
  79.     );
  80. }
  81. add_action( 'widgets_init', 'jiewu_widgets_init' );
  82.  
  83.  
  84. /**
  85.  * 禁止代码标点转换
  86.  */
  87. //remove_filter('the_content', 'wptexturize');
  88.  
  89.  
  90. /**
  91.  * 禁止整个文章自动添加p与br标签
  92.  */
  93. //remove_filter('the_content', 'wpautop');
  94. //remove_filter('the_excerpt', 'wpautop');
  95.  
  96.  
  97. //自动给文章的外部链接添加nofollow属性
  98. add_filter( 'the_content', 'web589_the_content_nofollow', 999 );
  99. function web589_the_content_nofollow( $content ) {
  100.     preg_match_all( '/href="(http.*?)"/', $content, $matches );
  101.     if ( $matches ) {
  102.         foreach ( $matches[1] as $val ) {
  103.             if ( strpos( $val, home_url() ) === false ) {
  104.                 $content = str_replace( "href=\"$val\"", "rel=\"nofollow\" href=\"" . get_bloginfo( 'wpurl' ) . "/go?url=" . base64_encode( $val ) . "\"", $content );
  105.             }
  106.         }
  107.     }
  108.  
  109.     return $content;
  110. }
  111.  
  112.  
  113. /**
  114.  * 当搜索结果只有一篇时直接重定向到日志
  115.  */
  116. add_action( 'template_redirect', 'cqr_redirect_single_post' );
  117. function cqr_redirect_single_post() {
  118.     if ( is_search() ) {
  119.         global $wp_query;
  120.         if ( $wp_query->post_count == 1 ) {
  121.             wp_redirect( get_permalink( $wp_query->posts['0']->ID ) );
  122.         }
  123.     }
  124. }
  125.  
  126.  
  127. /**
  128.  * WP 5.5 XML 站点地图中删除用户
  129.  */
  130. add_filter( 'wp_sitemaps_add_provider', function ( $provider, $name ) {
  131.     return ( $name == 'users' ) ? false : $provider;
  132. }, 10, 2 );
  133.  
  134.  
  135. /**
  136.  * 禁用 WooCommerce 块的 CSS 样式
  137.  */
  138. function themesharbor_disable_woocommerce_block_styles() {
  139.     wp_dequeue_style( 'wc-blocks-style' );
  140. }
  141.  
  142. add_action( 'wp_enqueue_scripts', 'themesharbor_disable_woocommerce_block_styles' );
  143.  
  144. /**
  145.  * WordPress完美禁止使用Gutenberg块编辑器并恢复到经典编辑器
  146.  */
  147.  
  148. /**
  149.  * WP >= 5.0 正式集成Gutenberg古腾堡编辑器
  150.  */
  151. if ( version_compare( get_bloginfo( 'version' ), '5.0', '>=' ) ) {
  152.     add_filter( 'use_block_editor_for_post', '__return_false' ); // 切换回之前的编辑器
  153.     remove_action( 'wp_enqueue_scripts', 'wp_common_block_scripts_and_styles' ); // 禁止前端加载样式文件
  154. } else {
  155.     /**
  156.      * 4.9.8 < WP < 5.0 插件形式集成Gutenberg古腾堡编辑器
  157.      */
  158.     add_filter( 'gutenberg_can_edit_post_type', '__return_false' );
  159. }
  160.  
  161. /**
  162.  * 小工具关闭Gutenberg古腾堡编辑器
  163.  */
  164.  
  165. function example_theme_support() {
  166.     remove_theme_support( 'widgets-block-editor' );
  167. }
  168.  
  169. add_action( 'after_setup_theme', 'example_theme_support' );
  170.  
  171.  
  172. /*删除 Gutenberg CSS */
  173. function brain1981_remove_wp_block_library_css() {
  174.     //WP Core
  175.     wp_dequeue_style( 'wp-block-library' );
  176.     wp_dequeue_style( 'wp-block-library-theme' );
  177.     //WooCommerce
  178.     wp_dequeue_style( 'wc-blocks-vendors-style' );
  179.     wp_dequeue_style( 'wc-block-editor' );
  180.     //BuddyPress
  181.     wp_dequeue_style( 'bp-member-block' );
  182.     wp_dequeue_style( 'wc-block-style' );
  183.     wp_dequeue_style( 'global-styles' );
  184.     wp_dequeue_style( 'bp-members-block' );
  185. }
  186.  
  187. add_action( 'wp_enqueue_scripts', 'brain1981_remove_wp_block_library_css', 100 );
  188.  
  189. /**
  190.  * 禁用 Auto Embeds 功能,Auto Embeds 基本不支持国内网站,禁用,加快页面解析速度。
  191.  */
  192. remove_filter( 'the_content', array( $GLOBALS['wp_embed'], 'run_shortcode' ), 8 );
  193. remove_filter( 'the_content', array( $GLOBALS['wp_embed'], 'autoembed' ), 8 );
  194. remove_action( 'pre_post_update', array( $GLOBALS['wp_embed'], 'delete_oembed_caches' ) );
  195. remove_action( 'edit_form_advanced', array( $GLOBALS['wp_embed'], 'maybe_run_ajax_cache' ) );
  196.  
  197. /**
  198.  * 屏蔽文章 Embed 功能,添加带embed或视频链接到编辑器中,转不会被转换。
  199.  */
  200. remove_action( 'rest_api_init', 'wp_oembed_register_route' );
  201. remove_filter( 'rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4 );
  202. add_filter( 'embed_oembed_discover', '__return_false' );
  203. remove_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10 );
  204. remove_filter( 'oembed_response_data', 'get_oembed_response_data_rich', 10, 4 );
  205. remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
  206. remove_action( 'wp_head', 'wp_oembed_add_host_js' );
  207. add_filter( 'tiny_mce_plugins', 'cqr_disable_post_embed_tiny_mce_plugin' );
  208. function cqr_disable_post_embed_tiny_mce_plugin( $plugins ) {
  209.     return array_diff( $plugins, array( 'wpembed' ) );
  210. }
  211.  
  212. add_filter( 'query_vars', 'cqr_disable_post_embed_query_var' );
  213. function cqr_disable_post_embed_query_var( $public_query_vars ) {
  214.     return array_diff( $public_query_vars, array( 'embed' ) );
  215. }
  216.  
  217.  
  218. // 缓存获取附件的月份。
  219. add_filter( 'media_library_months_with_files', function ( $months ) {
  220.     $months = get_transient( 'doocii_media_library_months' );
  221.  
  222.     if ( $months === false ) {
  223.         global $wpdb;
  224.  
  225.         $months = $wpdb->get_results( "SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC" );
  226.  
  227.         set_transient( 'doocii_media_library_months', $months, WEEK_IN_SECONDS );
  228.     }
  229.  
  230.     return $months;
  231. } );
  232.  
  233. // 删除附件月份的缓存
  234. function doocii_delete_media_library_months_cache() {
  235.     delete_transient( 'doocii_media_library_months' );
  236. }
  237.  
  238. add_action( 'edit_attachment', 'doocii_delete_media_library_months_cache' );
  239. add_action( 'add_attachment', 'doocii_delete_media_library_months_cache' );
  240. add_action( 'delete_attachment', 'doocii_delete_media_library_months_cache' );
  241.  
  242.  
  243. /**
  244.  * 移除 WordPress 头部加载 DNS 预获取(dns-prefetch)
  245.  */
  246. function remove_dns_prefetch( $hints, $relation_type ) {
  247.     if ( 'dns-prefetch' === $relation_type ) {
  248.         return array_diff( wp_dependencies_unique_hosts(), $hints );
  249.     }
  250.  
  251.     return $hints;
  252. }
  253.  
  254. add_filter( 'wp_resource_hints', 'remove_dns_prefetch', 10, 2 );
  255.  
  256.  
  257. /**
  258.  * 彻底关闭 pingback
  259.  */
  260. add_filter( 'xmlrpc_methods', 'cqr_xmlrpc_methods' );
  261. function cqr_xmlrpc_methods( $methods ) {
  262.     $methods['pingback.ping']                    = '__return_false';
  263.     $methods['pingback.extensions.getPingbacks'] = '__return_false';
  264.  
  265.     return $methods;
  266. }
  267.  
  268. //禁用 pingbacks, enclosures, trackbacks
  269. remove_action( 'do_pings', 'do_all_pings', 10, 1 );
  270. //去掉 _encloseme 和 do_ping 操作。
  271. remove_action( 'publish_post', '_publish_post_hook', 5, 1 );
  272.  
  273.  
  274. /**
  275.  * 隐藏版本信息
  276.  */
  277. function change_footer_admin() {
  278.     return '';
  279. }
  280.  
  281. add_filter( 'admin_footer_text', 'change_footer_admin', 9999 );
  282. function change_footer_version() {
  283.     return ' ';
  284. }
  285.  
  286. add_filter( 'update_footer', 'change_footer_version', 9999 );
  287.  
  288.  
  289. /**
  290.  * 去除后台首页面板的功能
  291.  */
  292. add_action( 'wp_dashboard_setup', 'cqr_remove_dashboard_widgets' );
  293. function cqr_remove_dashboard_widgets() {
  294.     global $wp_meta_boxes;
  295.     unset( $wp_meta_boxes['dashboard']['normal'] );
  296.     unset( $wp_meta_boxes['dashboard']['side'] );
  297. }
  298.  
  299. /**
  300.  * 文章修订版本
  301.  */
  302. add_filter( 'wp_revisions_to_keep', 'specs_wp_revisions_to_keep', 10, 2 );
  303. function specs_wp_revisions_to_keep( $num, $post ) {
  304.     return 3;
  305. }
  306.  
  307.  
  308. /**
  309.  * 自定义仪表板
  310.  * 删除这些Dashboard构件
  311.  */
  312. function remove_dashboard_widgets() {
  313.     global $wp_meta_boxes;
  314.     unset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press'] );
  315.     unset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links'] );
  316.     unset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now'] );
  317.     unset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins'] );
  318.     unset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_drafts'] );
  319.     unset( $wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments'] );
  320.     unset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_primary'] );
  321.     unset( $wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary'] );
  322. }
  323.  
  324. // add_action( 'wp_dashboard_setup', 'remove_dashboard_widgets', 11 );
  325.  
  326.  
  327. /**
  328.  * 去除头部冗余
  329.  */
  330. remove_action( 'wp_head', 'feed_links', 2 ); //移除feed
  331. remove_action( 'wp_head', 'feed_links_extra', 3 ); //移除feed
  332. remove_action( 'wp_head', 'rsd_link' ); //移除离线编辑器开放接口
  333. remove_action( 'wp_head', 'wlwmanifest_link' ); //移除离线编辑器开放接口
  334. remove_action( 'wp_head', 'index_rel_link' ); //去除本页唯一链接信息
  335. remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); //清除前后文信息
  336. remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); //清除前后文信息
  337. remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
  338. // remove_action('wp_head', 'locale_stylesheet');
  339. remove_action( 'publish_future_post', 'check_and_publish_future_post', 10, 1 );
  340. remove_action( 'wp_head', 'noindex', 1 );
  341. remove_action( 'wp_head', 'wp_generator' ); //移除WordPress版本
  342. remove_action( 'wp_head', 'rel_canonical' );
  343. remove_action( 'wp_footer', 'wp_print_footer_scripts' );
  344. remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
  345. remove_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );
  346. function my_remove_recent_comments_style() {
  347.     global $wp_widget_factory;
  348.     remove_action( 'wp_head', array(
  349.         $wp_widget_factory->widgets['WP_Widget_Recent_Comments'],
  350.         'recent_comments_style'
  351.     ) );
  352. }
  353.  
  354. add_action( 'widgets_init', 'my_remove_recent_comments_style' );
  355.  
  356.  
  357. /**
  358.  * 移除wp-json链接
  359.  */
  360. add_filter( 'rest_enabled', '_return_false' );
  361. add_filter( 'rest_jsonp_enabled', '_return_false' );
  362. remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
  363. remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );
  364.  
  365.  
  366. /**
  367.  * 管理员栏中去除的菜单项并关闭logo
  368.  */
  369. function wps_admin_bar( $wp_admin_bar ) {
  370.     $wp_admin_bar->remove_node( 'wp-logo' );
  371.     $wp_admin_bar->remove_node( 'about' );
  372.     $wp_admin_bar->remove_node( 'wporg' );
  373.     $wp_admin_bar->remove_node( 'documentation' );
  374.     $wp_admin_bar->remove_node( 'support-forums' );
  375.     $wp_admin_bar->remove_node( 'feedback' );
  376.     $wp_admin_bar->remove_node( 'view-site' );
  377. }
  378.  
  379. add_action( 'admin_bar_menu', 'wps_admin_bar', 25 );
  380.  
  381. /**
  382.  * 去后台标题中的“—— WordPress”
  383.  */
  384.  
  385. function doocii_custom_admin_title( $admin_title, $title ) {
  386.     return $title . ' ‹ ' . get_bloginfo( 'name' );
  387. }
  388.  
  389. add_filter( 'admin_title', 'doocii_custom_admin_title', 10, 2 );
  390.  
  391. /**
  392.  * 新标签打开顶部网站链接
  393.  */
  394. function _admin_site_ctrlenter() {
  395.     echo '<script type="text/javascript">
  396.     var sitelink = document.getElementById("wp-admin-bar-site-name").getElementsByClassName("ab-item");
  397.         for(var i=0;i<sitelink.length;i++)
  398.     { sitelink[i].target = "_blank"; }
  399.         </script>';
  400. }
  401.  
  402. ;
  403. add_action( 'admin_footer', '_admin_site_ctrlenter' );
  404.  
  405. /**
  406.  * 关闭emoji表情
  407.  */
  408. function disable_emojis() {
  409.     remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
  410.     remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
  411.     remove_action( 'wp_print_styles', 'print_emoji_styles' );
  412.     remove_action( 'admin_print_styles', 'print_emoji_styles' );
  413.     remove_filter( 'the_content_feed', 'wp_staticize_emoji' );
  414.     remove_filter( 'comment_text_rss', 'wp_staticize_emoji' );
  415.     remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' );
  416.     add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' );
  417. }
  418.  
  419. add_action( 'init', 'disable_emojis' );
  420.  
  421. function disable_emojis_tinymce( $plugins ) {
  422.     if ( is_array( $plugins ) ) {
  423.         return array_diff( $plugins, array(
  424.             'wpemoji'
  425.         ) );
  426.     } else {
  427.         return array();
  428.     }
  429. }
  430.  
  431.  
  432. /**
  433.  * 修改后台文字
  434.  */
  435. function theme_change_label_names( $translated_text ) {
  436.     if ( is_admin() ) {
  437.         switch ( $translated_text ) {
  438.  
  439.             case '将文章置于首页顶端' :
  440.                 $translated_text = __( '置顶', 'theme_text_domain' );
  441.                 break;
  442.         }
  443.     }
  444.  
  445.     return $translated_text;
  446. }
  447.  
  448. // add_filter( 'gettext', 'theme_change_label_names' );
  449.  
  450.  
  451.  
  452. /**
  453.  * 文章页面外链自动添加nofollow属性和新窗口打开
  454.  */
  455. function cn_nf_url_parse( $content ) {
  456.     $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>";
  457.     if ( preg_match_all( "/$regexp/siU", $content, $matches, PREG_SET_ORDER ) ) {
  458.         if ( ! empty( $matches ) ) {
  459.             $srcUrl = get_option( 'siteurl' );
  460.             for ( $i = 0; $i < count( $matches ); $i ++ ) {
  461.                 $tag      = $matches[ $i ][0];
  462.                 $tag2     = $matches[ $i ][0];
  463.                 $url      = $matches[ $i ][0];
  464.                 $noFollow = '';
  465.                 $pattern  = '/target\s*=\s*"\s*_blank\s*"/';
  466.                 preg_match( $pattern, $tag2, $match, PREG_OFFSET_CAPTURE );
  467.                 if ( count( $match ) < 1 ) {
  468.                     $noFollow .= ' target="_blank" ';
  469.                 }
  470.                 $pattern = '/rel\s*=\s*"\s*[n|d]ofollow\s*"/';
  471.                 preg_match( $pattern, $tag2, $match, PREG_OFFSET_CAPTURE );
  472.                 if ( count( $match ) < 1 ) {
  473.                     $noFollow .= ' rel="nofollow" ';
  474.                 }
  475.                 $pos = strpos( $url, $srcUrl );
  476.                 if ( $pos === false ) {
  477.                     $tag     = rtrim( $tag, '>' );
  478.                     $tag     .= $noFollow . '>';
  479.                     $content = str_replace( $tag2, $tag, $content );
  480.                 }
  481.             }
  482.         }
  483.     }
  484.     $content = str_replace( ']]>', ']]>', $content );
  485.  
  486.     return $content;
  487. }
  488.  
  489. add_filter( 'the_content', 'cn_nf_url_parse' );
  490.  
  491. /**
  492.  * 删除后台头部菜单
  493.  */
  494. function remove_admin_bar_links() {
  495.     global $wp_admin_bar;
  496.     $wp_admin_bar->remove_menu( 'wp-logo' );          // logo
  497.     $wp_admin_bar->remove_menu( 'about' );            // 关于WordPress
  498.     //$wp_admin_bar->remove_menu('search');           // 搜索
  499.     $wp_admin_bar->remove_menu( 'customize' );        // 删除关于WordPress链接
  500.     $wp_admin_bar->remove_menu( 'wporg' );            // 删除WordPress.org链接
  501.     $wp_admin_bar->remove_menu( 'documentation' );    // 删除WordPress文档链接
  502.     //$wp_admin_bar->remove_menu('support-forums');   // 删除支持论坛链接
  503.     //$wp_admin_bar->remove_menu('feedback');         // 删除反馈链接
  504.     //$wp_admin_bar->remove_menu('site-name');        // 删除站点名称菜单
  505.     //$wp_admin_bar->remove_menu('view-site');        // 删除查看网站链接
  506.     $wp_admin_bar->remove_menu( 'updates' );          // 删除更新链接
  507.     $wp_admin_bar->remove_menu( 'comments' );         // 删除评论链接
  508.     //$wp_admin_bar->remove_menu('new-content');      // 删除新建链接
  509.     //$wp_admin_bar->remove_menu('w3tc');             // 如果您使用w3总缓存删除性能链接
  510.     //$wp_admin_bar->remove_menu('my-account');       // 删除用户详细信息选项卡
  511. }
  512.  
  513. add_action( 'wp_before_admin_bar_render', 'remove_admin_bar_links' );
  514.  
  515.  
  516. /**
  517.  * 替换评论头像
  518.  **/
  519. define( 'DEFAULT_AVATAR_URL', get_template_directory_uri() . '/functions/assets/images/gravatar.png' );
  520.  
  521. function no_gravatars( $avatar ) {
  522.     return preg_replace( "/http.*?gravatar\.com[^\']*/", DEFAULT_AVATAR_URL, $avatar );
  523. }
  524.  
  525. add_filter( 'get_avatar', 'no_gravatars' );
  526.  
  527.  
  528. /**
  529.  * 定义主题路径
  530.  */
  531. function ts() {
  532.     echo get_template_directory_uri();
  533. }
  534.  
  535.  
  536. function pw_show_gallery_image_urls( $content ) {
  537.  
  538.     global $post;
  539.  
  540.     // Only do this on singular items
  541.     if ( ! is_singular() ) {
  542.         return $content;
  543.     }
  544.  
  545.     // Make sure the post has a gallery in it
  546.     if ( ! has_shortcode( $post->post_content, '' ) ) {
  547.         return $content;
  548.     }
  549.  
  550.     // Retrieve all galleries of this post
  551.     $galleries = get_post_galleries_images( $post );
  552.  
  553.     $image_list = '<ul>';
  554.  
  555.     // Loop through all galleries found
  556.     foreach ( $galleries as $gallery ) {
  557.  
  558.         // Loop through each image in each gallery
  559.         foreach ( $gallery as $image ) {
  560.  
  561.             $image_list .= '<li>' . $image . '</li>';
  562.  
  563.         }
  564.  
  565.     }
  566.  
  567.     $image_list .= '</ul>';
  568.  
  569.     // Append our image list to the content of our post
  570.     $content .= $image_list;
  571.  
  572.     return $content;
  573.  
  574. }
  575.  
  576. add_filter( 'the_content', 'pw_show_gallery_image_urls' );
  577.  
  578. /**
  579.  * 自定义回复内容列表
  580.  *
  581.  * @param  [type] $comment [description]
  582.  * @param  [type] $args    [description]
  583.  * @param  [type] $depth   [description]
  584.  *
  585.  * @return [type]          [description]
  586.  */
  587. function mytheme_comment( $comment, $args, $depth ) {
  588.     if ( 'div' === $args['style'] ) {
  589.         $tag       = 'div';
  590.         $add_below = 'comment';
  591.     } else {
  592.         $tag       = 'li';
  593.         $add_below = 'div-comment';
  594.     } ?>
  595.     <<?php echo $tag; ?><?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?> id="comment-<?php comment_ID() ?>"><?php
  596.     if ( 'div' != $args['style'] ) { ?>
  597.         <div class="comment-author">
  598.             <?php
  599.             if ( $args['avatar_size'] != 0 ) {
  600.                 echo get_avatar( $comment, $args['avatar_size'] );
  601.             }
  602.             ?>
  603.         </div>
  604.         <div id="div-comment-<?php comment_ID() ?>" class="comment-body"><?php
  605.     } ?>
  606.     <h4><?php
  607.         printf( __( '<cite class="fn">%s</cite>' ), get_comment_author_link() ); ?>
  608.     </h4>
  609.  
  610.     <!--
  611.             <div class="comment-num">01.</div> -->
  612.     <div class="clearfix"></div>
  613.     <?php comment_text(); ?>
  614.  
  615.     <?php
  616.     if ( $comment->comment_approved == '0' ) { ?>
  617.         <em class="comment-awaiting-moderation">提交成功,您的评论正在等待审核</em><br/><?php
  618.     } ?>
  619.     <div class="comment-meta commentmetadata">
  620.         <a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ); ?>"><?php
  621.             /* translators: 1: date, 2: time */
  622.             printf(
  623.                 __( '%1$s at %2$s' ),
  624.                 get_comment_date(),
  625.                 get_comment_time()
  626.             ); ?>
  627.         </a>
  628.  
  629.         <?php
  630.         edit_comment_link( __( '(编辑)' ), '  ', '' ); ?>
  631.     </div>
  632.     <div class="comment-body_dec"></div>
  633.  
  634.  
  635.     <div class="reply"><?php
  636.     comment_reply_link(
  637.         array_merge(
  638.             $args,
  639.             array(
  640.                 'reply_text' => __( '<i class="fas fa-reply"></i>' ),
  641.                 'add_below'  => $add_below,
  642.                 'depth'      => $depth,
  643.                 'max_depth'  => $args['max_depth']
  644.             )
  645.         )
  646.     ); ?>
  647.     </div><?php
  648.     if ( 'div' != $args['style'] ) : ?>
  649.         </div><?php
  650.     endif;
  651. }
  652.  
  653. /**
  654.  * 评论框删除网址栏
  655.  */
  656.  
  657. add_filter( 'comment_form_default_fields', 'website_remove' );
  658. function website_remove( $fields ) {
  659.     if ( isset( $fields['url'] ) ) {
  660.         unset( $fields['url'] );
  661.     }
  662.  
  663.     return $fields;
  664. }
  665.  
  666. /**
  667.  * 重新将评论表单排序
  668.  */
  669.  
  670. function move_comment_field_to_bottom( $fields ) {
  671.     $comment_field = $fields['comment'];
  672.     unset( $fields['comment'] );
  673.     $fields['comment'] = $comment_field;
  674.  
  675.     return $fields;
  676. }
  677.  
  678. add_filter( 'comment_form_fields', 'move_comment_field_to_bottom' );
  679.  
  680.  
  681. /**
  682.  * 删除发表评论四个字
  683.  */
  684. add_filter( 'comment_form_defaults', 'wpse33039_form_defaults' );
  685. function wpse33039_form_defaults( $defaults ) {
  686.     $defaults['title_reply'] = '';
  687.  
  688.     return $defaults;
  689. }
  690.  
  691.  
  692. function posts_link_next_class( $format ) {
  693.     $format = str_replace( 'href=', 'class="rn clean-gray" href=', $format );
  694.  
  695.     return $format;
  696. }
  697.  
  698. add_filter( 'next_post_link', 'posts_link_next_class' );
  699.  
  700. function posts_link_prev_class( $format ) {
  701.     $format = str_replace( 'href=', 'class="ln clean-gray" href=', $format );
  702.  
  703.     return $format;
  704. }
  705.  
  706. add_filter( 'previous_post_link', 'posts_link_prev_class' );
  707.  
  708. /**
  709.  * 删除分类目录标签的文字
  710.  */
  711.  
  712. add_filter( 'get_the_archive_title', function ( $title ) {
  713.     if ( is_category() ) {
  714.         $title = single_cat_title( '', false );
  715.     } elseif ( is_tag() ) {
  716.         $title = single_tag_title( '', false );
  717.     } elseif ( is_author() ) {
  718.         $title = '<span class="vcard">' . get_the_author() . '</span>';
  719.     } elseif ( is_tax() ) { //for custom post types
  720.         $title = sprintf( __( '%1$s' ), single_term_title( '', false ) );
  721.     } elseif ( is_post_type_archive() ) {
  722.         $title = post_type_archive_title( '', false );
  723.     }
  724.  
  725.     return $title;
  726. } );
  727.  
  728.  
  729. // function my_function_admin_bar(){ return false; }
  730. // add_filter( 'show_admin_bar' , 'my_function_admin_bar');
  731.  
  732. /**
  733.  * jiewu functions and definitions
  734.  *
  735.  * @link https://developer.wordpress.org/themes/basics/theme-functions/
  736.  *
  737.  * @package jiewu
  738.  */
  739.  
  740. if ( ! defined( '_S_VERSION' ) ) {
  741.     // Replace the version number of the theme on each release.
  742.     define( '_S_VERSION', '1.0.0' );
  743. }
  744.  
  745.  
  746. /* ————————————————————————————————————|   后台   |————————————————————————————————————*/
  747.  
  748.  
  749. /**
  750.  * 后台logo
  751.  */
  752. function my_login_logo_one() {
  753.     ?>
  754.     <style type="text/css">
  755.         body.login div#login h1 a {
  756.  
  757.         <?php
  758.             $img = get_field('favicon','option');
  759.             if( !empty( $img ) ): ?> background-image: url(<?php echo esc_url($img['url']); ?>);
  760.         <?php endif; ?> width: auto;
  761.             background-size: 80px;
  762.         }
  763.     </style>
  764.     <?php
  765. }
  766.  
  767. add_action( 'login_enqueue_scripts', 'my_login_logo_one' );
  768.  
  769.  
  770. function custom_login() {
  771.     $files = '<link rel="stylesheet" href="' . get_bloginfo( 'template_directory' ) . '/functions/assets/css/login.css" />';
  772.     echo $files;
  773. }
  774.  
  775. add_action( 'login_head', 'custom_login' );
  776.  
  777. // 后台logo链接
  778. function mb_login_url() {
  779.     return home_url();
  780. }
  781.  
  782. add_filter( 'login_headerurl', 'mb_login_url' );
  783.  
  784. // 后台logo title
  785. function mb_login_title() {
  786.     return get_option( 'blogname' );
  787. }
  788.  
  789. add_filter( 'login_headertext', 'mb_login_title' );
  790.  
  791.  
  792. /**
  793.  * 设置主题默认值并注册对各种WordPress功能的支持。
  794.  */
  795. function jiewu_setup() {
  796.     // 多语言支持
  797.     load_theme_textdomain( 'jiewu', get_template_directory() . '/languages' );
  798.  
  799.  
  800.     /*
  801.     * 让WordPress管理文档标题。
  802.     */
  803.     add_theme_support( 'title-tag' );
  804.  
  805.     /*
  806.     * 启用文章和页面上的缩略图的支持。
  807.     */
  808.     add_theme_support( 'post-thumbnails' );
  809.     add_image_size( 'news-list-m', 400, 300, true );
  810.     add_image_size( 'user-list-thumb-demo', 300, 400, true );
  811.     add_image_size( 'core-team-post-thumb', 370, 490, true );
  812.  
  813.  
  814.     // 注册网站导航
  815.     register_nav_menus(
  816.         array(
  817.             'header-menu-1' => esc_html__( 'header-navigation-1', 'jiewu' ),
  818.         )
  819.     );
  820.  
  821.  
  822.     // bootstrap 导航
  823.     function menu_set_dropdown( $sorted_menu_items, $args ) {
  824.         $last_top = 0;
  825.         foreach ( $sorted_menu_items as $key => $obj ) {
  826.             // it is a top lv item?
  827.             if ( 0 == $obj->menu_item_parent ) {
  828.                 //设置父项的键
  829.                 $last_top = $key;
  830.             } else {
  831.                 $sorted_menu_items[ $last_top ]->classes['dropdown'] = 'dropdown';
  832.             }
  833.         }
  834.  
  835.         return $sorted_menu_items;
  836.     }
  837.  
  838.     add_filter( 'wp_nav_menu_objects', 'menu_set_dropdown', 10, 2 );
  839.  
  840.  
  841. }
  842.  
  843. add_action( 'after_setup_theme', 'jiewu_setup' );
  844.  
  845.  
  846.  
  847. //添加自定义仪表盘小工具
  848. add_action('wp_dashboard_setup', 'quhenet_dashboard_widgets');
  849. function quhenet_dashboard_widgets() {
  850. global $wp_meta_boxes;
  851. wp_add_dashboard_widget('custom_help_widget', 'Theme Support', 'custom_dashboard_help');
  852. }
  853. function custom_dashboard_help() {
  854. echo '<p>感谢您支持正版,主题使用过程中如有任何问题,欢迎同我们取得联系。</p><p><a href="http://4x4.run/qihang" target="_blank">主题帮助</a>、<a href="http://4x4.run/qihang-as" target="_blank">售后中心</a><p>觉得主题不错,请介绍给有需要的朋友。</p>';
  855. }
  856. /* 移除评论菜单 */
  857. function quhenet_remove_menus(){
  858.   remove_menu_page( 'edit-comments.php' );  
  859. }
  860. add_action( 'admin_menu', 'quhenet_remove_menus' );
  861.  
  862.  
  863.  
File Description
  • 1231
  • PHP Code
  • 02 Dec-2022
  • 25.68 Kb
You can Share it: