現在「完了」、進捗 0%。工程は全3件中 3件完了。
最新報告「Slackの投稿通知のフォーマット見本」(2024-03-21 17:57:39)
index 詳細
https://www.notion.so/index-84fd979c8130485fbf69b56f346d7711
担当:大磯さん
https://plus-company.jp/portal/index/
pspt / pc2312!
ユーザー名: team-creative
パスワード: 8#T(p9jWcd9%F)L)CR#iurEU
▼FTP情報
ホスト:35.74.192.97
ユーザー:plus-company
パスワード:Rhd#Gk3ST7wU
ディレクトリパス:/plus-company/public_html/portal/index/wp/wp-content/themes/plus-index
Slackでの配信機能は、5月配信予定なので、4月下旬確認
中田
https://gyazo.com/0a5a28816cc64f04ece6bf2327659c49
中田
(1).httpasswdに追加
cron:iSerpQOuiKojY
(2)cron設定
10,20,30,40,50,0 * * * *
curl -u cron:plustest https://plus-company.jp/portal
(3)wp-config.php追記
define( 'ALTERNATE_WP_CRON', true );
(4)functions/common.php追記
// デバッグ情報をログファイルに記録する関数
function slack_notifier_debug_log($message) {
$log_file = ABSPATH . 'wp-content/debug-log.txt';
file_put_contents($log_file, date('[Y-m-d H:i:s] ') . $message . "\n", FILE_APPEND);
}
// Slack にメッセージを送信する関数
function send_to_slack($message) {
slack_notifier_debug_log("Slackに通知を試みます。メッセージ: " . $message);
$webhook_url = SLACK_WEBHOOK_URL;
$payload = json_encode(array("text" => $message));
$ch = curl_init($webhook_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($payload))
);
$result = curl_exec($ch);
$err = curl_error($ch);
curl_close($ch);
if ($result === false) {
slack_notifier_debug_log("Slackへの通知に失敗しました。CURLエラー: " . $err);
} else {
slack_notifier_debug_log("Slackへの通知が成功しました。");
}
}
// 投稿が公開されたときに Slack に通知する
function notify_slack_on_publish($new_status, $old_status, $post) {
if ('publish' === $new_status) {
// ACFフィールド 'post__notification' の値を取得
$should_notify = get_field('post__notification', $post->ID);
// チェックボックスが真であれば通知を送る
if ($should_notify) {
$title = get_the_title($post->ID);
$url = get_permalink($post->ID);
$excerpt = wp_trim_words($post->post_content, 18, '...');
$message = "新しい投稿が公開されました:\n*{$title}*\n{$excerpt} [続きを読む]($url)";
send_to_slack($message);
}
}
}
add_action('transition_post_status', 'notify_slack_on_publish', 10, 3);
以下の機能2点を設定しました
③記事ごとの閲覧率表示
スクショ:
https://gyazo.com/e725f6080467ca4654ad94d4592b3d48
ページ:
https://plus-company.jp/portal/index/visitors_data/?post_id=2031
アクセス方法:
indexのwordpress管理ページにログインし、
投稿一覧ページからアクセスします。
https://plus-company.jp/portal/index/wp/wp-admin/edit.php
閲覧内容を確認したい記事の項目の一番右にある閲覧率の数値のリンクからアクセスします。
https://gyazo.com/01afd85184ac611287bb51051fa241ea
②記事を閲覧したユーザーの履歴取得(CSVでダウンロード)
“③記事ごとの閲覧率表示“のページの下部の赤色のボタンから
CSVのダウンロードが可能です。
https://gyazo.com/295a0a591606fd65610e1be340ff9868
ページ例:
https://plus-company.jp/portal/index/visitors_data/?post_id=2031
CSVの内容:
https://gyazo.com/f788cc790b8bc702b024970947eb85a9