WordPressで本文の自動分割

add_filter('content_pagination',function($pages, $post){
  if(!is_single()){return $pages;}
  $pages = explodePost($pages,$post);
  return $pages;
},10,2);

function explodePost($pages, $post){
  if(get_post_meta($post->ID,'mp_switch',true)){return $pages;}
  $content = $post->post_content;
  if(strpos($content,'//act.ballooon.jp/imp/imp')){ // for ballooon counter
    return $pages;
  }
  $len = mb_strlen($content,'utf-8');
  $insert = "<!--nextpage-->";
  $width  = 3000;
  if($len/$width<2){
    return $pages;
  }
  $content = preg_replace("/\r\n|\r|\n/", "\n", $content);
  $st = $width;
  foreach(range(1,(int)($len/$width)) as $i){
    if($st > $len){ break; }
    $content = preg_replace("/^.{0,$st}.+\?\n\n\K/us", $insert, $content);
    $st = mb_strrpos($content,$insert,0,'utf-8')+$width;
  }
  // pattern blockquate
  $pat = sprintf("/(<blockquote[^>]*>.*)%s(.*<\/blockquote>)/isu",preg_quote($insert,'/'));
  $content = preg_replace($pat,'${1}${2}',$content);

  $pat = sprintf("/%s(.{0,%d})$/isu",preg_quote($insert,'/'),$width/2);
  $content = preg_replace($pat,'${1}${2}',$content);

  $return = explode($insert,$content);
  $return = array_filter($return,'strlen');
  $return = array_values($return);
  if(!$return[0]){ return $pages; }
  return $return;
}

NginxでGETパラメーターを使ってbasic認証の条件分岐

  location ~* /wp-login\.php|/wp-admin/.*\.php$ {
    set $auth_basic "INPUT ID & PASSWORD";
    if ($arg_action = 'postpass') {
      set $auth_basic off;
    }
    auth_basic $auth_basic;
    auth_basic_user_file /etc/nginx/conf.d/htpasswd;

    fastcgi_pass   unix:/run/php/php7.4-fpm.sock;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
  }

WordPressの関連記事をカテゴリーとタグからプラグインなしで取得する(自作)

global $wpdb;
$sql = 'SELECT object_id,COUNT(object_id) AS c FROM wp_term_relationships WHERE term_taxonomy_id IN (SELECT term_taxonomy_id FROM wp_term_relationships WHERE object_id = '.get_the_ID().') GROUP BY object_id ORDER BY c DESC, object_id DESC LIMIT 12;';
$object = $wpdb->get_results($sql);
$ids = [];
foreach($object as $v){
  if(get_the_ID() == $v->object_id){
    continue;
  }
  $ids[] = $v->object_id;
}
$params = [
'post_type' => 'post',
'include'=> $ids,
'orderby' => 'post__in',
];
$relposts = get_posts($params);
foreach ( array_slice($relposts,0,6) as $post ) :
  setup_postdata( $post );
endforeach;


SELECT object_id,COUNT(object_id) AS c FROM wp_term_relationships WHERE term_taxonomy_id IN (SELECT term_taxonomy_id FROM wp_term_relationships WHERE object_id = '.get_the_ID().') GROUP BY object_id ORDER BY c DESC, object_id DESC LIMIT 12;

このSQLが肝
このSQLでterm一覧を取得しその中の記事を集計して関連度の高い順に取得している
includeを使うとexcludeが効かないので取得時に除外
記事数も制御できないのでarray_sliceでカット
多めに取得しているのは非公開記事や固定ページを弾くため

Google Apps Scriptでサーバを監視しメール通知

/* サイトを監視し、ダウンしてたらメール通知 */

const URL = 'https://wp.wkbr.net'; // 監視したいサイトのURL
const EMAIL = 'wkbr@gmail.com'; // エラーを知らせるメールアドレス
var   message;

function main() {
  if(isUrlActive()) {
    Logger.log('正常に作動しています'); // ログに出力
  } else {
    Logger.log('サイトエラー'); // ログに出力
    sendMail();
  }
}

function isUrlActive() {
  try {
    const response = UrlFetchApp.fetch(URL);
    message = 'responsecode = ' + response.getResponseCode();
    return (response.getResponseCode() == 200);
  } catch (e) {
    Logger.log(e); 
    message = e;
    return false;
  }
}

function sendMail() {
  const dateTime = Utilities.formatDate(new Date(), 'JST', 'yyyy年MM月dd日 HH:mm');
  MailApp.sendEmail({
    to: EMAIL,
    subject: '【サイトダウン】検知しました',
    htmlBody: `
      以下のURLでサイトダウンを検知しました。<hr>
      URL: <a href="${URL}">${URL}</a><br>
      日時: ${dateTime} <br>
      ${message}`
  });
}

参考サイト

Reno5Aの初期設定

※自分用のメモ

googleログインやアプリのアプデはしておく

adguard,gcam(googlecamera)のインストール

gcam adgurd

アプリの削除(調整中) adbの使い方

adb shell pm uninstall -k –user 0 com.agoda.mobile.consumer
adb shell pm uninstall -k –user 0 com.facebook.system
adb shell pm uninstall -k –user 0 com.facebook.appmanager
adb shell pm uninstall -k –user 0 com.facebook.services
adb shell pm uninstall -k –user 0 com.facebook.katana
adb shell pm uninstall -k –user 0 com.google.android.youtube
adb shell pm uninstall -k –user 0 com.google.android.apps.youtube.music
adb shell pm uninstall -k –user 0 com.google.android.videos
adb shell pm uninstall -k –user 0 com.google.android.apps.podcasts
adb shell pm uninstall -k –user 0 com.google.android.keep
adb shell pm uninstall -k –user 0 com.google.android.apps.photos
adb shell pm uninstall -k –user 0 com.google.android.apps.googleassistant
adb shell pm uninstall -k –user 0 com.google.android.googlequicksearchbox
adb shell pm uninstall -k –user 0 com.google.android.apps.nbu.files
adb shell pm uninstall -k –user 0 com.coloros.backuprestore
adb shell pm uninstall -k –user 0 com.coloros.gamespaceui
adb shell pm uninstall -k –user 0 com.coloros.childrenspace
adb shell pm uninstall -k –user 0 com.coloros.soundrecorder
adb shell pm uninstall -k –user 0 com.coloros.videoeditor
adb shell pm uninstall -k –user 0 com.coloros.karaoke

adb shell pm uninstall -k –user 0 com.google.android.apps.wellbeing
adb shell pm uninstall -k –user 0 com.google.android.apps.docs
adb shell pm uninstall -k –user 0 com.google.android.gms.location.history
adb shell pm uninstall -k –user 0 com.google.android.apps.magazines
adb shell pm uninstall -k –user 0 com.google.android.apps.subscriptions.red
adb shell pm uninstall -k –user 0 com.google.ar.core
adb shell pm uninstall -k –user 0 com.heytap.cloud
adb shell pm uninstall -k –user 0 com.heytap.pictorial
adb shell pm uninstall -k –user 0 com.heytap.music
adb shell pm uninstall -k –user 0 com.coloros.musiclink
adb shell pm uninstall -k –user 0 com.coloros.relax
adb shell pm uninstall -k –user 0 com.coloros.weather2
:adb shell pm uninstall -k –user 0 com.coloros.weather.service 消すと再起動を繰り返すので生かす
adb shell pm uninstall -k –user 0 com.coloros.athena
adb shell pm uninstall -k –user 0 com.coloros.phonemanager
adb shell pm uninstall -k –user 0 com.caf.fmradio

adb shell pm uninstall -k –user 0 com.felicanetworks.mfm.main

adb shell pm uninstall -k –user 0 com.oppo.usercenter
adb shell pm uninstall -k –user 0 com.oppo.sos