Addons.php
8 years ago
Columns.php
8 years ago
Help.php
8 years ago
Settings.php
8 years ago
Upgrade.php
8 years ago
Welcome.php
8 years ago
Help.php
331 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | class AC_Admin_Page_Help extends AC_Admin_Page { |
| 8 | |
| 9 | const TRANSIENT_COUNT_KEY = 'ac-deprecated-message-count'; |
| 10 | |
| 11 | private $messages = array(); |
| 12 | |
| 13 | public function __construct() { |
| 14 | |
| 15 | $this |
| 16 | ->set_slug( 'help' ) |
| 17 | ->set_label_with_count(); |
| 18 | |
| 19 | // Hide page when there are no messages |
| 20 | if ( ! $this->get_message_count() ) { |
| 21 | $this->set_show_in_menu( false ); |
| 22 | } |
| 23 | |
| 24 | // Init and request |
| 25 | add_action( 'admin_init', array( $this, 'init' ), 9 ); |
| 26 | add_action( 'admin_init', array( $this, 'run_hooks_on_help_tab' ) ); |
| 27 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) ); |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @return $this |
| 32 | */ |
| 33 | private function set_label_with_count() { |
| 34 | $label = __( 'Help', 'codepress-admin-columns' ); |
| 35 | |
| 36 | if ( $count = $this->get_message_count() ) { |
| 37 | $label .= '<span class="ac-badge">' . $count . '</span>'; |
| 38 | } |
| 39 | |
| 40 | $this->set_label( $label ); |
| 41 | |
| 42 | return $this; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Run all hooks once |
| 47 | */ |
| 48 | public function init() { |
| 49 | if ( ! AC()->user_can_manage_admin_columns() ) { |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | // Run once |
| 54 | if ( false === $this->get_message_count() ) { |
| 55 | $this->run_hooks(); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Run all hooks when opening the help tab. |
| 61 | */ |
| 62 | public function run_hooks_on_help_tab() { |
| 63 | if ( ! AC()->user_can_manage_admin_columns() || ! $this->is_current_screen() ) { |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | $this->run_hooks(); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Admin scripts |
| 72 | */ |
| 73 | public function admin_scripts() { |
| 74 | if ( $this->is_current_screen() ) { |
| 75 | wp_enqueue_style( 'ac-admin-page-help-css', AC()->get_plugin_url() . 'assets/css/admin-page-help' . AC()->minified() . '.css', array(), AC()->get_version() ); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | private function update_message_count() { |
| 80 | $count = count( $this->get_messages( 'filter' ) ) + count( $this->get_messages( 'action' ) ); |
| 81 | |
| 82 | set_transient( self::TRANSIENT_COUNT_KEY, $count, WEEK_IN_SECONDS ); |
| 83 | } |
| 84 | |
| 85 | private function get_message_count() { |
| 86 | return get_transient( self::TRANSIENT_COUNT_KEY ); |
| 87 | } |
| 88 | |
| 89 | public function delete_message_count() { |
| 90 | delete_transient( self::TRANSIENT_COUNT_KEY ); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * This will run all deprecated hooks and adds a message when a hook has been used on the site. |
| 95 | */ |
| 96 | public function run_hooks() { |
| 97 | |
| 98 | $types = array( 'post', 'user', 'comment', 'link', 'media' ); |
| 99 | $post_types = get_post_types(); |
| 100 | |
| 101 | $columns = array(); |
| 102 | foreach ( AC()->get_list_screens() as $ls ) { |
| 103 | foreach ( $ls->get_column_types() as $column ) { |
| 104 | $columns[ $column->get_type() ] = $column->get_type(); |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | // Filters |
| 109 | |
| 110 | $this->deprecated_filter( 'cac/headings/label', '3.0', 'cac-columns-custom' ); |
| 111 | $this->deprecated_filter( 'cac/column/meta/value', '3.0', 'cac-column-meta-value' ); |
| 112 | $this->deprecated_filter( 'cac/column/meta/types', '3.0', 'cac-column-meta-types' ); |
| 113 | $this->deprecated_filter( 'cac/settings/tabs', '3.0', 'cac-settings-tabs' ); |
| 114 | $this->deprecated_filter( 'cac/editable/is_column_editable', '3.0', 'cac-editable-is_column_editable' ); |
| 115 | $this->deprecated_filter( 'cac/editable/editables_data', '3.0', 'cac-editable-editables_data' ); |
| 116 | $this->deprecated_filter( 'cac/editable/options', '3.0', 'cac-editable-editables_data' ); |
| 117 | $this->deprecated_filter( 'cac/inline-edit/ajax-column-save/value', '3.0', 'cac-inline-edit-ajax-column-save-value' ); |
| 118 | $this->deprecated_filter( 'cac/addon/filtering/options', '3.0', 'cac-addon-filtering-options' ); |
| 119 | $this->deprecated_filter( 'cac/addon/filtering/dropdown_top_label', '3.0', 'cac-addon-filtering-dropdown_top_label' ); |
| 120 | $this->deprecated_filter( 'cac/addon/filtering/taxonomy/terms_args', '3.0', 'cac-addon-filtering-taxonomy-terms_args' ); |
| 121 | $this->deprecated_filter( 'cac/addon/filtering/dropdown_empty_option', '3.0', 'cac-addon-filtering-taxonomy-terms_args' ); |
| 122 | $this->deprecated_filter( 'cac/column/actions/action_links', '3.0', 'cac-column_actions-action_links' ); |
| 123 | $this->deprecated_filter( 'cac/acf/format_acf_value', '3.0', 'cac-acf-format_acf_value' ); |
| 124 | $this->deprecated_filter( 'cac/addon/filtering/taxonomy/terms_args', '3.0' ); |
| 125 | $this->deprecated_filter( 'cac/column/meta/use_text_input', '3.0' ); |
| 126 | $this->deprecated_filter( 'cac/hide_renewal_notice', '3.0' ); |
| 127 | |
| 128 | $this->deprecated_filter( 'cac/columns/custom', '3.0', 'cac-columns-custom' ); |
| 129 | foreach ( $types as $type ) { |
| 130 | $this->deprecated_filter( 'cac/columns/custom/type=' . $type, '3.0', 'cac-columns-custom' ); |
| 131 | } |
| 132 | |
| 133 | foreach ( $post_types as $post_type ) { |
| 134 | $this->deprecated_filter( 'cac/columns/custom/post_type=' . $post_type, '3.0', 'cac-columns-custom' ); |
| 135 | } |
| 136 | |
| 137 | $this->deprecated_filter( 'cac/column/value', '3.0', 'cac-column-value' ); |
| 138 | foreach ( $types as $type ) { |
| 139 | $this->deprecated_filter( 'cac/column/value/' . $type, '3.0', 'cac-column-value' ); |
| 140 | } |
| 141 | |
| 142 | $this->deprecated_filter( 'cac/editable/column_value', '3.0', 'cac-editable-column_value' ); |
| 143 | foreach ( $columns as $column_type ) { |
| 144 | $this->deprecated_filter( 'cac/editable/column_value/column=' . $column_type, '3.0', 'cac-editable-column_value' ); |
| 145 | } |
| 146 | |
| 147 | $this->deprecated_filter( 'cac/editable/column_save', '3.0', 'cac-editable-column_save' ); |
| 148 | foreach ( $columns as $column_type ) { |
| 149 | $this->deprecated_filter( 'cac/editable/column_save/column=' . $column_type, '3.0', 'cac-editable-column_save' ); |
| 150 | } |
| 151 | |
| 152 | // Actions |
| 153 | $this->deprecated_action( 'cac/admin_head', '3.0', 'cac-admin_head' ); |
| 154 | $this->deprecated_action( 'cac/loaded', '3.0', 'cac-cacloaded' ); |
| 155 | $this->deprecated_action( 'cac/inline-edit/after_ajax_column_save', '3.0', 'cacinline-editafter_ajax_column_save' ); |
| 156 | $this->deprecated_action( 'cac/settings/after_title', '3.0' ); |
| 157 | $this->deprecated_action( 'cac/settings/form_actions', '3.0' ); |
| 158 | $this->deprecated_action( 'cac/settings/sidebox', '3.0' ); |
| 159 | $this->deprecated_action( 'cac/settings/form_columns', '3.0' ); |
| 160 | $this->deprecated_action( 'cac/settings/after_columns', '3.0' ); |
| 161 | $this->deprecated_action( 'cac/column/settings_meta', '3.0' ); |
| 162 | $this->deprecated_action( 'cac/settings/general', '3.0' ); |
| 163 | $this->deprecated_action( 'cpac_messages', '3.0' ); |
| 164 | $this->deprecated_action( 'cac/settings/after_menu', '3.0' ); |
| 165 | |
| 166 | $this->update_message_count(); |
| 167 | } |
| 168 | |
| 169 | private function get_groups() { |
| 170 | $groups = array( |
| 171 | 'filter' => __( 'Deprecated Filters', 'codepress-admin-columns' ), |
| 172 | 'action' => __( 'Deprecated Actions', 'codepress-admin-columns' ), |
| 173 | ); |
| 174 | |
| 175 | return $groups; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * @param string $hook |
| 180 | * @param string $version |
| 181 | * @param string|null $page_slug |
| 182 | */ |
| 183 | private function deprecated_filter( $hook, $version, $page_slug = null ) { |
| 184 | if ( has_filter( $hook ) ) { |
| 185 | $message = sprintf( __( 'The filter %s used on this website is deprecated since %s.', 'codepress-admin-columns' ), '<code>' . $hook . '</code>', '<strong>' . $version . '</strong>' ); |
| 186 | |
| 187 | $this->add_deprecated_message( 'filter', $message, $hook, 'filter-reference/' . $page_slug ); |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * @param string $hook |
| 193 | * @param string $version |
| 194 | * @param string|null $page_slug |
| 195 | */ |
| 196 | private function deprecated_action( $hook, $version, $page_slug = null ) { |
| 197 | if ( has_action( $hook ) ) { |
| 198 | $message = sprintf( __( 'The action %s used on this website is deprecated since %s.', 'codepress-admin-columns' ), '<code>' . $hook . '</code>', '<strong>' . $version . '</strong>' ); |
| 199 | |
| 200 | $this->add_deprecated_message( 'action', $message, $hook, 'action-reference/' . $page_slug ); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * @param string $type |
| 206 | * @param string $message |
| 207 | * @param string $hook |
| 208 | * @param null $page |
| 209 | */ |
| 210 | private function add_deprecated_message( $type, $message, $hook, $page = null ) { |
| 211 | if ( $callback_message = $this->get_callback_message( $hook ) ) { |
| 212 | $message .= ' ' . $callback_message; |
| 213 | } |
| 214 | if ( $page ) { |
| 215 | $message .= ' ' . $this->get_documention_link( $page ); |
| 216 | } |
| 217 | |
| 218 | $this->add_message( $message, $type ); |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * @param string $message |
| 223 | * @param string $type |
| 224 | */ |
| 225 | private function add_message( $message, $type = 'filter' ) { |
| 226 | $this->messages[ $type ][] = $message; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * @param string $type |
| 231 | * |
| 232 | * @return array|false |
| 233 | */ |
| 234 | private function get_messages( $type = 'filter' ) { |
| 235 | if ( ! isset( $this->messages[ $type ] ) ) { |
| 236 | return array(); |
| 237 | } |
| 238 | |
| 239 | return $this->messages[ $type ]; |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * @param string $page Website page slug |
| 244 | * |
| 245 | * @return false|string |
| 246 | */ |
| 247 | private function get_documention_link( $page ) { |
| 248 | return ac_helper()->html->link( ac_get_site_url( 'documentation/' . $page ), __( 'View documentation', 'codepress-admin-columns' ) . ' »', array( 'target' => '_blank' ) ); |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * @param string $hook Action or Filter |
| 253 | * |
| 254 | * @return array|false |
| 255 | */ |
| 256 | private function get_callbacks( $hook ) { |
| 257 | global $wp_filter; |
| 258 | |
| 259 | if ( ! isset( $wp_filter[ $hook ] ) ) { |
| 260 | return false; |
| 261 | } |
| 262 | |
| 263 | if ( empty( $wp_filter[ $hook ]->callbacks ) ) { |
| 264 | return false; |
| 265 | } |
| 266 | |
| 267 | $callbacks = array(); |
| 268 | |
| 269 | foreach ( $wp_filter[ $hook ]->callbacks as $callback ) { |
| 270 | foreach ( $callback as $cb ) { |
| 271 | |
| 272 | // Function |
| 273 | if ( is_scalar( $cb['function'] ) ) { |
| 274 | $callbacks[] = $cb['function']; |
| 275 | } |
| 276 | |
| 277 | // Method |
| 278 | if ( is_array( $cb['function'] ) ) { |
| 279 | $callbacks[] = get_class( $cb['function'][0] ) . '::' . $cb['function'][1]; |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | if ( ! $callbacks ) { |
| 285 | return false; |
| 286 | } |
| 287 | |
| 288 | return $callbacks; |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * @param string $hook Action or Filter |
| 293 | * |
| 294 | * @return string|false |
| 295 | */ |
| 296 | private function get_callback_message( $hook ) { |
| 297 | $callbacks = $this->get_callbacks( $hook ); |
| 298 | |
| 299 | if ( ! $callbacks ) { |
| 300 | return false; |
| 301 | } |
| 302 | |
| 303 | return sprintf( _n( 'The callback used is %s.', 'The callbacks used are %s', count( $callbacks ), 'codepress-admin-columns' ), '<code>' . implode( '</code>, <code>', $callbacks ) . '</code>' ); |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * Render help page |
| 308 | */ |
| 309 | public function display() { |
| 310 | ?> |
| 311 | <h2><?php _e( 'Help', 'codepress-admin-columns' ); ?></h2> |
| 312 | <p> |
| 313 | <?php _e( 'The Admin Columns plugin has undergone some major changes in version 4.', 'codepress-admin-columns' ); ?> <br/> |
| 314 | |
| 315 | <?php printf( __( 'This site is using some actions or filters that have changed. Please read %s to resolve them.', 'codepress-admin-columns' ), ac_helper()->html->link( ac_get_site_utm_url( 'documentation/faq/upgrading-from-v3-to-v4', 'help' ), __( 'our documentation', 'codepress-admin-columns' ) ) ); ?> |
| 316 | </p> |
| 317 | |
| 318 | <?php foreach ( $this->get_groups() as $type => $label ) { |
| 319 | if ( $messages = $this->get_messages( $type ) ) : ?> |
| 320 | <h3><?php echo esc_html( $label ); ?></h3> |
| 321 | <?php foreach ( $messages as $message ) : ?> |
| 322 | <div class="ac-deprecated-message"> |
| 323 | <p><?php echo $message; ?></p> |
| 324 | </div> |
| 325 | <?php endforeach; ?> |
| 326 | <?php endif; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | } |
| 331 |