PluginProbe ʕ •ᴥ•ʔ
SEO SIMPLE PACK / 2.2.3
SEO SIMPLE PACK v2.2.3
1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 2.0.0 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.4.0 2.4.1 2.4.2 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.3.0 3.3.1 3.4.0 3.5.0 3.5.1 3.5.2 3.6.0 3.6.1 3.6.2 3.6.3 3.7.0 trunk 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2
seo-simple-pack / class / hooks.php
seo-simple-pack / class Last commit date
trait 5 years ago __branch.php 5 years ago activate.php 5 years ago data.php 5 years ago hooks.php 5 years ago menu.php 5 years ago metabox.php 5 years ago output.php 5 years ago utility.php 5 years ago
hooks.php
202 lines
1 <?php
2 class SSP_Hooks {
3
4 /**
5 * 外部からのインスタンス化を防ぐ
6 */
7 private function __construct() {}
8
9 /**
10 * init
11 */
12 public static function init() {
13
14 add_action( 'init', [ 'SSP_Hooks', 'add_custom_settings' ], 99 ); // 確実に�
15 �部取得できるように後ろで発火
16 add_action( 'admin_enqueue_scripts', [ 'SSP_Hooks', 'include_files' ] );
17 add_action( 'admin_head', [ 'SSP_Hooks', 'hook_admin_head' ] );
18 add_action( 'template_redirect', [ 'SSP_Hooks', 'redirect' ], 1 );
19
20 // titleタグの除去
21 remove_action( 'wp_head', '_wp_render_title_tag', 1 );
22
23 // canonicalの削除
24 remove_action( 'wp_head', 'rel_canonical' );
25
26 // self::set_notification(); //OFF中
27 }
28
29
30 /**
31 * .dashicons-list-view が微妙にでかいので微調整
32 */
33 public static function hook_admin_head() {
34 echo '<style>.toplevel_page_ssp_main_setting .dashicons-list-view{transform: scale(.9) translateX(1px)}</style>';
35 }
36
37
38 /**
39 * CSS Scriptの読み込み
40 */
41 public static function include_files( $hook_suffix ) {
42
43 $is_index = 'index.php' === $hook_suffix;
44 $is_term = 'term.php' === $hook_suffix;
45 $is_editor_page = 'post.php' === $hook_suffix || 'post-new.php' === $hook_suffix;
46 $is_ssp_page = false !== strpos( $hook_suffix, 'ssp_' );
47
48 // SSP設定ページで読み込むファイル
49 if ( $is_ssp_page ) {
50
51 wp_enqueue_style( 'ssp-css', SSP_URL . 'dist/css/ssp.css', [], SSP_VERSION );
52 wp_enqueue_script( 'ssp-script', SSP_URL . 'dist/js/ssp.js', ['jquery' ], SSP_VERSION, true );
53
54 } elseif ( $is_editor_page ) {
55
56 wp_enqueue_style( 'ssp-post', SSP_URL . 'dist/css/post.css', [], SSP_VERSION );
57
58 } elseif ( $is_term ) {
59
60 wp_enqueue_style( 'ssp-term', SSP_URL . 'dist/css/term.css', [], SSP_VERSION );
61 }
62
63 // 設定ページでの�
64 �通ファイル
65 if ( $is_editor_page || $is_ssp_page || $is_term ) {
66 wp_enqueue_style( 'ssp-common', SSP_URL . 'dist/css/common.css', [], SSP_VERSION );
67
68 wp_enqueue_media();
69 wp_enqueue_script( 'ssp-media', SSP_URL . 'dist/js/mediauploader.js', ['jquery' ], SSP_VERSION, true );
70 wp_enqueue_script( 'ssp-common-script', SSP_URL . 'dist/js/common.js', ['jquery' ], SSP_VERSION, true );
71 }
72
73 // ダッシュボードでも読み込むファイル
74 if ( $is_index ) {
75 wp_enqueue_style( 'ssp-common', SSP_URL . 'dist/css/common.css', [], SSP_VERSION );
76 }
77
78 }
79
80
81
82 /**
83 * カスタム投稿タイプ・カスタムタクソノミー用を取得し、設定を追加
84 */
85 public static function add_custom_settings() {
86
87 if ( ! is_admin() ) return;
88
89 $added_new_data = false;
90 $args = [
91 'public' => true,
92 '_builtin' => false,
93 ];
94
95 $custom_post_types = get_post_types( $args, 'objects', 'and' ) ?: [];
96 foreach ( $custom_post_types as $key => $obj ) {
97 SSP_Data::$custom_post_types[ $key ] = $obj->label;
98 }
99
100 $custom_taxonomies = get_taxonomies( $args, 'objects', 'and' ) ?: [];
101 foreach ( $custom_taxonomies as $key => $obj ) {
102 SSP_Data::$custom_taxonomies[ $key ] = $obj->label;
103 }
104
105 // カスタム投稿 の設定追加
106 foreach ( SSP_Data::$custom_post_types as $pt_name => $label ) {
107 if ( ! isset( SSP_Data::$settings[ $pt_name . '_noindex' ] ) ) {
108 SSP_Data::$settings[ $pt_name . '_noindex' ] = SSP_Data::$default_pt_settings['noindex'];
109 SSP_Data::$settings[ $pt_name . '_title' ] = SSP_Data::$default_pt_settings['title'];
110 SSP_Data::$settings[ $pt_name . '_desc' ] = SSP_Data::$default_pt_settings['desc'];
111
112 $added_new_data = true;
113 }
114 }
115
116 // カスタムタクソノミー の設定追加
117 foreach ( SSP_Data::$custom_taxonomies as $tax_name => $label ) {
118 if ( ! isset( SSP_Data::$settings[ $tax_name . '_noindex' ] ) ) {
119 SSP_Data::$settings[ $tax_name . '_noindex' ] = SSP_Data::$default_tax_settings['noindex'];
120 SSP_Data::$settings[ $tax_name . '_title' ] = SSP_Data::$default_tax_settings['title'];
121 SSP_Data::$settings[ $tax_name . '_desc' ] = SSP_Data::$default_tax_settings['desc'];
122
123 $added_new_data = true;
124 }
125 }
126
127 // 新規追加�
128 目があった場合
129 if ( $added_new_data ) {
130 update_option( SSP_Data::DB_NAME['settings'], SSP_Data::$settings );
131 }
132
133 }
134
135
136 /**
137 * 使用しないページのリダイレクト処理
138 */
139 public static function redirect( $page ) {
140
141 $home = home_url();
142
143 if ( is_author() && SSP_Data::$settings['author_disable'] ) {
144 wp_safe_redirect( $home );
145 exit;
146 }
147
148 // check: /type/aside
149 if ( is_tax() && SSP_Data::$settings['post_format_disable'] ) {
150 if ( 'post_format' === get_queried_object()->taxonomy ) {
151 wp_safe_redirect( $home );
152 exit;
153 };
154 }
155 if ( is_attachment() && SSP_Data::$settings['attachment_disable'] ) {
156 wp_safe_redirect( get_post()->guid );
157 exit;
158 }
159 }
160
161
162 /**
163 * 更新に関する通知 :: 〜OFF中〜
164 */
165 private static function set_notification() {
166
167 /**
168 * プラグイン更新時、notification を show にセット
169 */
170 if ( get_option( SSP_Data::DB_NAME['notification'] ) !== 'hide' ) {
171 update_option( SSP_Data::DB_NAME['notification'], 'show' );
172 }
173
174 // phpcs:ignore WordPress.Security.NonceVerification.Missing
175 if ( isset( $_POST['ssp_notice_close'] ) ) {
176 // CLOSEボタン押された時
177 update_option( SSP_Data::DB_NAME['notification'], 'hide' );
178 }
179
180 // 以前から使用中の方へ向けてのメッセージ
181 $notification_db = get_option( SSP_Data::DB_NAME['notification'] );
182 if ( 'show' === $notification_db ) {
183 add_action( 'admin_notices', function() {
184 ?>
185 <div class="notice notice-error ssp-notice">
186 <p>
187 ~ 通知したいメッセージ ~
188 </p>
189 <form action="" method="post">
190 <button type="submit" name="ssp_notice_close" class="ssp-notice__closeBtn notice-dismiss">
191 <span>この通知を非表示にする</span>
192 </button>
193 </form>
194 </div>
195 <?php
196 } );
197 }
198
199 }
200
201 }
202