{"id":2149,"date":"2025-06-11T07:02:00","date_gmt":"2025-06-10T22:02:00","guid":{"rendered":"https:\/\/www.dogrow.net\/php\/?p=2149"},"modified":"2025-06-18T05:17:28","modified_gmt":"2025-06-17T20:17:28","slug":"blog82%e3%80%90wordpress%e3%80%91%e6%8a%95%e7%a8%bf%e3%80%81%e5%9b%ba%e5%ae%9a%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%94%e3%81%a8%e3%81%ae%e3%82%a2%e3%82%af%e3%82%bb%e3%82%b9%e3%82%ab%e3%82%a6%e3%83%b3","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/php\/blog82%e3%80%90wordpress%e3%80%91%e6%8a%95%e7%a8%bf%e3%80%81%e5%9b%ba%e5%ae%9a%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%94%e3%81%a8%e3%81%ae%e3%82%a2%e3%82%af%e3%82%bb%e3%82%b9%e3%82%ab%e3%82%a6%e3%83%b3\/","title":{"rendered":"(82)\u3010WORDPRESS\u3011\u500b\u3005\u306e\u6295\u7a3f\u3001\u56fa\u5b9a\u30da\u30fc\u30b8\u7528\u306e\u30a2\u30af\u30bb\u30b9\u30ab\u30a6\u30f3\u30bf\u3092\u4f5c\u308b\u3002"},"content":{"rendered":"<h1 class=\"my_h\">\u30101\u3011\u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p>\u5404\u6295\u7a3f\u3001\u5404\u56fa\u5b9a\u30da\u30fc\u30b8\u306b\u3064\u3044\u3066\u3001\u76f4\u8fd1 n\u65e5\u9593\u306e\u30a2\u30af\u30bb\u30b9\u6570\u3092\u8868\u793a\u3057\u305f\u3044\u3002<\/p>\n<h1 class=\"my_h\">\u30102\u3011\u3084\u3063\u3066\u307f\u305f<\/h1>\n<h2 class=\"my_h\">1) \u4ed5\u69d8<\/h2>\n<p>1) WORDPRESS\u306e Plugin\u3068\u3057\u3066\u5b9f\u88c5\u3059\u308b\u3053\u3068\u3002<\/p>\n<p>2) \u540c\u4e00IP\u304b\u3089\u306e\u91cd\u8907\u30a2\u30af\u30bb\u30b9\u306f 1\u65e5 1\u30ab\u30a6\u30f3\u30c8\u3068\u3059\u308b\u3053\u3068\u3002<\/p>\n<p>3) \u30c7\u30fc\u30bf\u306e\u683c\u7d0d\u5148\u3092 WORDPRESS\u304c\u4f7f\u7528\u3057\u3066\u3044\u308b Database\u3068\u3059\u308b\u3053\u3068\u3002<br \/>\n\u3000SQLite\u306b\u3057\u3088\u3046\u304b\u8ff7\u3063\u305f\u304c\u3001\u3059\u3067\u306b WORDPRESS\u5b9f\u884c\u306e\u305f\u3081\u306b PostgreSQL\u3068\u63a5\u7d9a\u6e08\u307f\u3067\u8ca0\u8377\u5897\u306e\u5fc3\u914d\u304c\u306a\u304f\u3001\u3053\u3061\u3089\u3092\u4f7f\u3046\u3053\u3068\u306b\u3057\u305f\u3002<\/p>\n<p>4) shortcode\u3067\u6295\u7a3f\u30da\u30fc\u30b8\u3084\u56fa\u5b9a\u30da\u30fc\u30b8\u306b\u8868\u793a\u3067\u304d\u308b\u3053\u3068\u3002<\/p>\n<p>5) shortcode\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u3067\u904e\u53bb n\u65e5\u3092\u6307\u5b9a\u3067\u304d\u308b\u3053\u3068\u3002<\/p>\n<p>6) BOT\u306b\u3088\u308b\u30a2\u30af\u30bb\u30b9\u3092\u9664\u5916\u3059\u308b\u3053\u3068\u3002<\/p>\n<h3 class=\"my_h\">(1) \u91cd\u8907\u30ab\u30a6\u30f3\u30c8\u56de\u907f\u306e\u65b9\u6cd5<\/h3>\n<p>\u30c6\u30fc\u30d6\u30eb\u306b\u5bfe\u3057\u3066 UNIQUE\u5236\u7d04\u3092\u8a2d\u5b9a\u3059\u308b\u3002<\/p>\n<pre class='my_pre'>\r\nUNIQUE KEY unique_view (post_id, ip_address, view_date)\r\n<\/pre>\n<p>\u3053\u308c\u306b\u3088\u308a\u3001post_id, ip_address, view_date \u306e 3\u30ab\u30e9\u30e0\u306e\u5024\u304c\u91cd\u8907\u3059\u308b\u30ec\u30b3\u30fc\u30c9\u306f\u5b58\u5728\u3067\u304d\u306a\u304f\u306a\u308b\u3002<\/p>\n<h2 class=\"my_h\">2) \u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h2>\n<pre class=\"brush: php; title: ytmr_pvcounter.php; notranslate\" title=\"ytmr_pvcounter.php\">\r\n&lt;?php\r\n\/*\r\nPlugin Name: YTMR PV Counter\r\nDescription: \u5404\u6295\u7a3f\u30fb\u56fa\u5b9a\u30da\u30fc\u30b8\u3078\u306e\u30a2\u30af\u30bb\u30b9\u6570\u3092\u65e5\u5225\u306b\u30ab\u30a6\u30f3\u30c8\u3057\u3001\u30b7\u30e7\u30fc\u30c8\u30b3\u30fc\u30c9\u3067\u8868\u793a\u3059\u308b\u3002\r\nVersion: 1.0\r\nAuthor: DOGROW.NET\r\n*\/\r\ndefined(&#039;ABSPATH&#039;) || exit;\r\nrequire_once plugin_dir_path(__FILE__) . &#039;includes\/functions.php&#039;;\r\nregister_activation_hook(__FILE__, &#039;pvc_create_table&#039;);\r\nadd_action(&#039;wp&#039;, &#039;pvc_track_pageview&#039;);\r\nadd_shortcode(&#039;ytmr_pv_counter&#039;, &#039;pvc_show_last_n_days&#039;);\r\n<\/pre>\n<pre class=\"brush: php; title: includes\/functions.php; notranslate\" title=\"includes\/functions.php\">\r\n&lt;?php\r\ndefined(&#039;ABSPATH&#039;) || exit;\r\n\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\nfunction pvc_create_table() {\r\n    global $wpdb;\r\n    $table_name = $wpdb-&gt;prefix . &#039;pageview_counter&#039;;\r\n    $charset_collate = $wpdb-&gt;get_charset_collate();\r\n\r\n    $sql = &quot;CREATE TABLE IF NOT EXISTS $table_name (\r\n        id BIGINT AUTO_INCREMENT PRIMARY KEY,\r\n        post_id BIGINT NOT NULL,\r\n        ip_address VARCHAR(45) NOT NULL,\r\n        view_date DATE NOT NULL,\r\n        UNIQUE KEY unique_view (post_id, ip_address, view_date)\r\n    ) $charset_collate;&quot;;\r\n\r\n    require_once ABSPATH . &#039;wp-admin\/includes\/upgrade.php&#039;;\r\n    dbDelta($sql);\r\n}\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\nfunction pvc_track_pageview() {\r\n    if(!is_singular(&#039;post&#039;) &amp;&amp; !is_singular(&#039;page&#039;)) return;\r\n    if(!isRealVisitor()) return;                                \/\/ BOT\u306a\u3089\u3070\u30ab\u30a6\u30f3\u30c8\u3057\u306a\u3044\u3002\r\n\r\n    global $wpdb;\r\n    $post_id = get_the_ID();\r\n    if (!$post_id) return;\r\n\r\n    $ip = $_SERVER&#x5B;&#039;REMOTE_ADDR&#039;] ?? &#039;unknown&#039;;\r\n    $today = date(&#039;Y-m-d&#039;);\r\n    $table = $wpdb-&gt;prefix . &#039;pageview_counter&#039;;\r\n\r\n    \/\/ \u540c\u4e00IP\u30fb\u65e5\u30fb\u6295\u7a3f\u306e\u7d44\u307f\u5408\u308f\u305b\u304c\u5b58\u5728\u3057\u306a\u3051\u308c\u3070\u8ffd\u52a0\r\n    $exists = $wpdb-&gt;get_var($wpdb-&gt;prepare(\r\n        &quot;SELECT COUNT(*) FROM $table WHERE post_id = %d AND ip_address = %s AND view_date = %s&quot;,\r\n        $post_id, $ip, $today\r\n    ));\r\n\r\n    if (!$exists) {\r\n        $wpdb-&gt;insert($table, &#x5B;\r\n            &#039;post_id&#039; =&gt; $post_id,\r\n            &#039;ip_address&#039; =&gt; $ip,\r\n            &#039;view_date&#039; =&gt; $today\r\n        ]);\r\n    }\r\n}\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\nfunction pvc_show_last_n_days($atts) {\r\n    if (!is_singular(&#039;post&#039;) &amp;&amp; !is_singular(&#039;page&#039;)) return &#039;&#039;;\r\n\r\n    $atts = shortcode_atts(&#x5B;&#039;n&#039; =&gt; 5], $atts);\r\n    $n = intval($atts&#x5B;&#039;n&#039;]);\r\n    if ($n &lt; 1 || $n &gt; 365) $n = 5;\r\n    \/\/$now = date(&#039;Y-m-d H:i:s&#039;);\r\n\r\n    global $wpdb;\r\n    $post_id = get_the_ID();\r\n    if (!$post_id) return &#039;&#039;;\r\n\r\n    $table = $wpdb-&gt;prefix . &#039;pageview_counter&#039;;\r\n    $output = &quot;&lt;div&gt;\u30a2\u30af\u30bb\u30b9\u6570\uff08\u76f4\u8fd1{$n}\u65e5\uff09: &quot;;\r\n    for ($i = 0; $i &lt; $n; $i++) {\r\n        $date = date(&#039;Y-m-d&#039;, strtotime(&quot;-$i days&quot;));\r\n        $count = $wpdb-&gt;get_var($wpdb-&gt;prepare(\r\n            &quot;SELECT COUNT(*) FROM $table WHERE post_id = %d AND view_date = %s&quot;,\r\n            $post_id, $date\r\n        ));\r\n        $output .= &quot;&lt;li&gt;{$date}: {$count}\u56de&lt;\/li&gt;&quot;;\r\n    }\r\n    $output .= &quot;&lt;\/ul&gt;&lt;\/div&gt;&quot;;\r\n    return $output;\r\n}\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\n\/\/ \u6295\u7a3f\u672c\u6587\u306e\u5f8c\u308d\u306b\u30ab\u30b9\u30bf\u30e0HTML\u3092\u8ffd\u52a0\u3059\u308b\r\nfunction mcf_add_custom_footer_message($content) {\r\n    \/\/ \u6295\u7a3f\u30da\u30fc\u30b8\uff08single\uff09\u306e\u307f\u5bfe\u8c61\u306b\u3059\u308b\r\n    if (is_single() &amp;&amp; is_main_query()) {\r\n        $add_content = pvc_show_last_n_days(null);\r\n        return $content.$add_content; \/\/ \u672c\u6587\u306e\u5f8c\u308d\u306b\u8ffd\u52a0\r\n    }\r\n    return $content;\r\n}\r\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\n\/\/ BOT\u5224\u5b9a\r\nfunction isRealVisitor() {\r\n    if (!isset($_SERVER&#x5B;&#039;HTTP_USER_AGENT&#039;])) {\r\n        return false;  \/\/ User-Agent\u304c\u306a\u3044\uff1dBOT\u306e\u53ef\u80fd\u6027\u5927\r\n    }\r\n    $ua = strtolower($_SERVER&#x5B;&#039;HTTP_USER_AGENT&#039;]);\r\n    \/\/ \u3088\u304f\u77e5\u3089\u308c\u305fBOT\u306e\u30ad\u30fc\u30ef\u30fc\u30c9\uff08\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u8ffd\u52a0\u53ef\uff09\r\n    $bot_keywords = &#x5B;\r\n        &#039;bot&#039;,          \/\/ \u4e00\u822c\u7684\u306abot\uff08Googlebot, Bingbot\u306a\u3069\uff09\r\n        &#039;crawler&#039;,      \/\/ \u30af\u30ed\u30fc\u30e9\u30fc\r\n        &#039;spider&#039;,       \/\/ \u30b9\u30d1\u30a4\u30c0\u30fc\u7cfb\r\n        &#039;slurp&#039;,        \/\/ Yahoo\r\n        &#039;baiduspider&#039;,  \/\/ Baidu\r\n        &#039;yandex&#039;,       \/\/ Yandex\r\n        &#039;ia_archiver&#039;,  \/\/ Alexa\r\n        &#039;python-requests&#039;, \/\/ Python\u306b\u3088\u308b\u30a2\u30af\u30bb\u30b9\r\n        &#039;wget&#039;,\r\n        &#039;curl&#039;,\r\n        &#039;httpclient&#039;,\r\n        &#039;libwww-perl&#039;,\r\n    ];\r\n    foreach ($bot_keywords as $bot) {\r\n        if (strpos($ua, $bot) !== false) {\r\n            return false;  \/\/ BOT\u304c\u542b\u307e\u308c\u3066\u3044\u308b\u306e\u3067\u9664\u5916\r\n        }\r\n    }\r\n    return true;  \/\/ BOT\u3067\u306f\u306a\u3044\u3068\u5224\u5b9a\r\n}\r\n<\/pre>\n<h2 class=\"my_h\">3) \u52d5\u4f5c\u78ba\u8a8d<\/h2>\n<p>\u3053\u3053\uff08\u2193\uff09\u306b\u8868\u793a\u3057\u3066\u307f\u308b\u3002<br \/>\n<\/p>\n<h1 class=\"my_h\">\u30103\u3011\u6b8b\u4ef6<\/h1>\n<p>BOT\u306b\u3088\u308b\u30a2\u30af\u30bb\u30b9\u3092\u9664\u5916\u3059\u308b\u3053\u3068\u3002<br \/>\n\u203b\u30da\u30fc\u30b8\u53f3\u4e0a\u306e\u7dcf\u5408\u30ab\u30a6\u30f3\u30bf\u306f\u5bfe\u5fdc\u6e08\u307f\u3002\u3053\u306e\u30b3\u30fc\u30c9\u3092\u79fb\u690d\u3059\u308b\u3002<\/p>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>\u30101\u3011\u3084\u308a\u305f\u3044\u3053\u3068 \u5404\u6295\u7a3f\u3001\u5404\u56fa\u5b9a\u30da\u30fc\u30b8\u306b\u3064\u3044\u3066\u3001\u76f4\u8fd1 n\u65e5\u9593\u306e\u30a2\u30af\u30bb\u30b9\u6570\u3092\u8868\u793a\u3057\u305f\u3044\u3002 \u30102\u3011\u3084\u3063\u3066\u307f\u305f 1) \u4ed5\u69d8 1) WORDPRESS\u306e Plugin\u3068\u3057\u3066\u5b9f\u88c5\u3059\u308b\u3053\u3068\u3002 2) \u540c\u4e00IP\u304b\u3089\u306e\u91cd\u8907\u30a2\u30af\u30bb\u30b9\u306f 1\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/php\/blog82%e3%80%90wordpress%e3%80%91%e6%8a%95%e7%a8%bf%e3%80%81%e5%9b%ba%e5%ae%9a%e3%83%9a%e3%83%bc%e3%82%b8%e3%81%94%e3%81%a8%e3%81%ae%e3%82%a2%e3%82%af%e3%82%bb%e3%82%b9%e3%82%ab%e3%82%a6%e3%83%b3\/\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-2149","post","type-post","status-publish","format-standard","hentry","category-wordpress"],"views":1049,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/2149","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/comments?post=2149"}],"version-history":[{"count":9,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/2149\/revisions"}],"predecessor-version":[{"id":2173,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/posts\/2149\/revisions\/2173"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/media?parent=2149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/categories?post=2149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/php\/wp-json\/wp\/v2\/tags?post=2149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}