WordPress でテーマフォルダを公開する危険性について

php

1<?php2// ↓ ここから追記3// rel="prev"とrel=“next"表示の削除4remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');5 6// WordPressバージョン表示の削除7remove_action('wp_head', 'wp_generator');8 9// 絵文字表示のための記述削除(絵文字を使用しないとき)10remove_action('wp_head', 'print_emoji_detection_script', 7);11remove_action('wp_print_styles', 'print_emoji_styles');12 13// アイキャッチ画像の有効化14add_theme_support('post-thumbnails');15 16// 投稿固定ページを旧式のエディターに戻す17add_filter('gutenberg_can_edit_post_type', '__return_false'); //Gutenbergプラグイン用18add_filter('use_block_editor_for_post', '__return_false'); //WordPressブロックエディター用19 20//従来のウィジェットエディターに戻す21function example_theme_support()22{23 remove_theme_support('widgets-block-editor');24}25add_action('after_setup_theme', 'example_theme_support');26 27// ウィジェット追加28if (function_exists('register_sidebar')) {29 register_sidebar(array(30 'name' => 'ウィジェット1',31 'id' => 'widget01',32 'before_widget' => '<div class=”widget”>',33 'after_widget' => '</div>',34 'before_title' => '<h3>',35 'after_title' => '</h3>'36 ));37}38 39// 自動成型削除40function my_tiny_mce_before_init($init_array)41{42 global $allowedposttags;43 $init_array['valid_elements'] = '*[*]';44 $init_array['extended_valid_elements'] = '*[*]';45 $init_array['valid_children'] = '+a[' . implode('|', array_keys($allowedposttags)) . ']';46 // $init_array['indent'] = true;47 if (is_page()) {48 $init_array['wpautop'] = false;49 $init_array['force_p_newlines'] = false;50 }51 return $init_array;52}53add_filter('tiny_mce_before_init', 'my_tiny_mce_before_init');54 55function custom_print_scripts() {56 if (!is_admin()) {57 //デフォルトjquery削除58 wp_deregister_script('jquery');59 60 //GoogleCDNから読み込む61 wp_enqueue_script('jquery-js', '//ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js' );62 wp_enqueue_script('archive-js', get_template_directory_uri() . '/js/archive.js');63 }64}65add_action('wp_print_scripts', 'custom_print_scripts');66 67//ヘッダーにCDNを読み込ませる68function fontawesome_enqueue(){69 wp_enqueue_script('fontawesome_script', 'https://kit.fontawesome.com/82bcc49272.js'); 70}71add_action('wp_enqueue_scripts','fontawesome_enqueue');72 73function register_stylesheet() {74 wp_register_style('reset', get_template_directory_uri().'/css/destyle.css');75 wp_register_style('style', get_template_directory_uri().'/css/style.css');76 wp_register_style('base', 'https://use.fontawesome.com/releases/v6.2.0/css/all.css');77}78function add_stylesheet() {79 register_stylesheet();80 wp_enqueue_style('reset', '', array(), '1.0', false);81 wp_enqueue_style('style', '', array(), '1.0', false);82 wp_enqueue_style('base', '', array(), '1.0', false);83}84 add_action('wp_enqueue_scripts', 'add_stylesheet');85 86/*---- Google Icon ----*/87function add_google_icons() {88wp_register_style( 'googleFonts',89'https://fonts.googleapis.com/icon?family=Material+Icons'90);91wp_enqueue_style( 'googleFonts');92}93add_action( 'wp_enqueue_scripts', 'add_google_icons' );94 95//PHPをウィジェット追加96function widget_text_exec_php( $widget_text ) {97 if( strpos( $widget_text, '<' . '?' ) !== false ) {98 ob_start();99 eval( '?>' . $widget_text );100 $widget_text = ob_get_contents();101 ob_end_clean();102 }103 return $widget_text;104}105add_filter( 'widget_text', 'widget_text_exec_php', 99 );106 107// カスタマイズコメントフォーム108if (!function_exists('custom_comment_form')) {109 function custom_comment_form($args)110 {111 // 「コメントを残す」を削除112 $args['title_reply'] = '';113 //コメント欄の前に表示する文字列の削除 ※デフォルトではコメント114 $args['comment_field'] = '<p class="comment-form-comment"><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>';115 //「admin としてログイン中。ログアウトしますか ? * が付いている欄は必須項目です」を削除116 $args['logged_in_as'] = '';117 // 「メールアドレスが公開されることはありません」を削除118 $args['comment_notes_before'] = '';119 return $args;120 }121}122 123add_filter('comment_form_defaults', 'custom_comment_form');124// カスタマイズコメントフォームフィールド125if (!function_exists('custom_comment_form_fields')) {126 function custom_comment_form_fields($arg)127 {128 // コメントからウェブサイトとEmailを削除129 $arg['url'] = '';130 $arg['email'] = '';131 return $arg;132 }133}134add_filter('comment_form_default_fields', 'custom_comment_form_fields');135 136// ----------------------------------------------------------------------------137// コメント欄の名前が未入力の場合の投稿者名138// ----------------------------------------------------------------------------139function default_author_name($author, $comment_ID, $comment) {140 if ($author == __('Anonymous')) {141 $author = '名無しさん';142 }143 144 return $author;145}146add_filter('get_comment_author', 'default_author_name', 10, 3);147 148// 検索ワードファイルパス149define('SEARCH_WORDS_FILE_PATH', __DIR__.'/test.csv');150 151 152/* 投稿と固定ページ一覧にスラッグの列を追加 */153function add_posts_columns_slug($columns) {154 $columns['slug'] = 'スラッグ';155 echo '';156 return $columns;157}158add_filter( 'manage_posts_columns', 'add_posts_columns_slug' );159add_filter( 'manage_pages_columns', 'add_posts_columns_slug' );160 161/* スラッグを表示 */162function custom_posts_columns_slug($column_name, $post_id) {163 if( $column_name == 'slug' ) {164 $post = get_post($post_id);165 $slug = $post->post_name;166 echo esc_attr($slug);167 }168}169add_action( 'manage_posts_custom_column', 'custom_posts_columns_slug', 10, 2 );170add_action( 'manage_pages_custom_column', 'custom_posts_columns_slug', 10, 2 );171 172 173//アイキャッチを有効化174add_theme_support( 'post-thumbnails' );175 176//画像サイズ追加177add_image_size('rect', 640, 400, true);178 179//画像URLからIDを取得180function get_attachment_id_by_url( $url ) {181global $wpdb;182$sql = "SELECT ID FROM {$wpdb->posts} WHERE post_name = %s";183preg_match( '/([^\/]+?)(-e\d+)?(-\d+x\d+)?(\.\w+)?$/', $url, $matches );184$post_name = $matches[1];185return ( int )$wpdb->get_var( $wpdb->prepare( $sql, $post_name ) );186}187 188//画像をサムネイルで出力189function catch_that_image() {190global $post;191$first_img = '';192$output = preg_match_all( '/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches );193$first_img_src = $matches[1][0];194$attachment_id = get_attachment_id_by_url( $first_img_src );195$first_img = wp_get_attachment_image( $attachment_id, 'rect', false, array( 'class' => 'archive-thumbnail' ) );196if( empty( $first_img ) ){197 $first_img = '<img class="attachment_post_thumbnail" src="' . get_stylesheet_directory_uri() . '/assets/img/common/no-img.jpg" alt="No image" />';198}199return $first_img;200}201 202add_filter('use_block_editor_for_post', '__return_false');203add_theme_support('post-thumbnails');204?>

コメントを投稿

0 コメント