[WP]qTranslate X Cleanup to single language

<?php// qTranslate X Cleanup to single language// 1: database backup [important!!!]// 2: settings -> language ->[Import/Export] -> [Convert database to the "square bracket only" style.]check -> SaveChanges// 3: this code paste to functions.php// 4: reload your site// 5: delete this code from functions.php// 6: Remove qTranslate pluginglobal $post;$language = 'en'; // Language you want to keep$args = array( 'post_type' => array('post','page'), // Change if necessary 'post_status' => array('publish','pending','draft','auto-draft','future','private','inherit','trash'), // Change if necessary 'posts_per_page' => 9999999, 'offset' => 0, 'orderby' => 'ID', 'order' => 'ASC', 'suppress_filters' => true, 's'=> '[:]');$posts_array = get_posts( $args );foreach ( $posts_array as $post ) : setup_postdata( $post ); $post->post_content = qtrans_use($language, $post->post_content,false); $post->post_title = qtrans_use($language, $post->post_title,false); wp_update_post($post); $count++;endforeach;wp_reset_postdata();

[WP] Google Analytics Dashboard for WP (GADWP) の認証が突然切断される場合の応急処置

<?php/** * functions.phpに書いてね */// Google Analytics Dashboard for WP (GADWP) 専用処理// トラッキングコードをテーマ側での出力するため、プラグインの処理は停止function oc_wp_loaded_gadwp() { if ( class_exists( 'GADWP_Tracking' ) && function_exists( 'GADWP' ) ) { $oc_gadwp_plugin = GADWP(); if ( isset($oc_gadwp_plugin->tracking) && isset($oc_gadwp_plugin->tracking->analytics) ) { // GoogleAnalyticsコード出力用のアクションのみを取り除く remove_action( 'wp_head', array( $oc_gadwp_plugin->tracking->analytics, 'output' ), 99 ); remove_action( 'wp_footer', array( $oc_gadwp_plugin->tracking->analytics, 'output' ), 99 ); } }}add_action('wp_loaded', 'oc_wp_loaded_gadwp', 99);// GoogleAnalyticsコードの出力function oc_google_analytics() { ?> <script> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-XXXXXXXX-1', 'auto'); ga('send', 'pageview'); </script><?php}add_action( 'wp_head', 'oc_google_analytics', 999 );

WordPressのプラグインで、get_template_part的なものを使いたい

<?php// wp-content/plugins/wp-onocom-plugin.php class wp_onocom_plugin { static $instance = null; function __construct(){ self::$instance = $this; } public static function get_instance() { if( self::$instance != null ) { return self::$instance; } else { return new self(); } } public function get_plugin_template_part($slug, $name = null) { $templates = array(); $name = (string) $name; if ( '' !== $name ) $templates[] = "{$slug}-{$name}.php"; $templates[] = "{$slug}.php"; $located = ''; foreach ( (array) $templates as $template_name ) { if ( !$template_name ) { continue; } if ( file_exists($this->get_plugin_path() . '/' . $template_name) ) { $located = $this->get_plugin_path() . '/' . $template_name; break; } } if($located) { require_once( $located ); } } public function get_plugin_url() { return plugins_url("",__FILE__); } public function get_plugin_path() { return dirname(__FILE__); }}