Hooks.php
166 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Deprecated; |
| 4 | |
| 5 | use AC\Deprecated\Hook\Action; |
| 6 | use AC\Deprecated\Hook\Filter; |
| 7 | use AC\ListScreenTypes; |
| 8 | use AC\Transient; |
| 9 | |
| 10 | class Hooks { |
| 11 | |
| 12 | /** |
| 13 | * @param bool $force_update |
| 14 | * |
| 15 | * @return int |
| 16 | */ |
| 17 | public function get_count( $force_update = false ) { |
| 18 | $cache = new Transient( 'ac-deprecated-message-count' ); |
| 19 | |
| 20 | if ( $force_update || $cache->is_expired() ) { |
| 21 | $cache->save( $this->get_deprecated_count(), WEEK_IN_SECONDS ); |
| 22 | } |
| 23 | |
| 24 | return (int) $cache->get(); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * @return Filter[] |
| 29 | */ |
| 30 | private function get_filters() { |
| 31 | $hooks = [ |
| 32 | new Filter( 'cac/headings/label', '3.0', 'cac-columns-custom' ), |
| 33 | new Filter( 'cac/column/meta/value', '3.0', 'cac-column-meta-value' ), |
| 34 | new Filter( 'cac/column/meta/types', '3.0', 'cac-column-meta-types' ), |
| 35 | new Filter( 'cac/settings/tabs', '3.0', 'cac-settings-tabs' ), |
| 36 | new Filter( 'cac/editable/is_column_editable', '3.0', 'cac-editable-is_column_editable' ), |
| 37 | new Filter( 'cac/editable/editables_data', '3.0', 'cac-editable-editables_data' ), |
| 38 | new Filter( 'cac/editable/options', '3.0', 'cac-editable-editables_data' ), |
| 39 | new Filter( 'cac/inline-edit/ajax-column-save/value', '3.0', 'cac-inline-edit-ajax-column-save-value' ), |
| 40 | new Filter( 'cac/addon/filtering/options', '3.0', 'cac-addon-filtering-options' ), |
| 41 | new Filter( 'cac/addon/filtering/dropdown_top_label', '3.0', 'cac-addon-filtering-dropdown_top_label' ), |
| 42 | new Filter( 'cac/addon/filtering/taxonomy/terms_args', '3.0', 'cac-addon-filtering-taxonomy-terms_args' ), |
| 43 | new Filter( 'cac/addon/filtering/dropdown_empty_option', '3.0', 'cac-addon-filtering-taxonomy-terms_args' ), |
| 44 | new Filter( 'cac/column/actions/action_links', '3.0', 'cac-column_actions-action_links' ), |
| 45 | new Filter( 'cac/acf/format_acf_value', '3.0', 'cac-acf-format_acf_value' ), |
| 46 | new Filter( 'cac/addon/filtering/taxonomy/terms_args', '3.0' ), |
| 47 | new Filter( 'cac/column/meta/use_text_input', '3.0' ), |
| 48 | new Filter( 'cac/hide_renewal_notice', '3.0' ), |
| 49 | new Filter( 'acp/network_settings/groups', '3.4' ), |
| 50 | new Filter( 'acp/settings/groups', '3.4' ), |
| 51 | ]; |
| 52 | |
| 53 | $hooks[] = new Filter( 'cac/columns/custom', '3.0', 'cac-columns-custom' ); |
| 54 | |
| 55 | foreach ( $this->get_types() as $type ) { |
| 56 | $hooks[] = new Filter( 'cac/columns/custom/type=' . $type, '3.0', 'cac-columns-custom' ); |
| 57 | } |
| 58 | |
| 59 | foreach ( get_post_types() as $post_type ) { |
| 60 | $hooks[] = new Filter( 'cac/columns/custom/post_type=' . $post_type, '3.0', 'cac-columns-custom' ); |
| 61 | } |
| 62 | |
| 63 | $hooks[] = new Filter( 'cac/column/value', '3.0', 'cac-column-value' ); |
| 64 | |
| 65 | foreach ( $this->get_types() as $type ) { |
| 66 | $hooks[] = new Filter( 'cac/column/value/' . $type, '3.0', 'cac-column-value' ); |
| 67 | } |
| 68 | |
| 69 | $hooks[] = new Filter( 'cac/editable/column_value', '3.0', 'cac-editable-column_value' ); |
| 70 | |
| 71 | foreach ( $this->get_columns() as $column_type ) { |
| 72 | $hooks[] = new Filter( 'cac/editable/column_value/column=' . $column_type, '3.0', 'cac-editable-column_value' ); |
| 73 | } |
| 74 | |
| 75 | $hooks[] = new Filter( 'cac/editable/column_save', '3.0', 'cac-editable-column_save' ); |
| 76 | |
| 77 | foreach ( $this->get_columns() as $column_type ) { |
| 78 | $hooks[] = new Filter( 'cac/editable/column_save/column=' . $column_type, '3.0', 'cac-editable-column_save' ); |
| 79 | } |
| 80 | |
| 81 | return $hooks; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @return array |
| 86 | */ |
| 87 | private function get_types() { |
| 88 | return [ 'post', 'user', 'comment', 'link', 'media' ]; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * @return array |
| 93 | */ |
| 94 | private function get_columns() { |
| 95 | $columns = []; |
| 96 | foreach ( ListScreenTypes::instance()->get_list_screens() as $list_screen ) { |
| 97 | foreach ( $list_screen->get_column_types() as $column ) { |
| 98 | $column_type = $column->get_type(); |
| 99 | |
| 100 | $columns[ $column_type ] = $column_type; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | return $columns; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * @return Hook[] |
| 109 | */ |
| 110 | private function get_actions() { |
| 111 | return [ |
| 112 | new Action( 'cac/admin_head', '3.0', 'cac-admin_head' ), |
| 113 | new Action( 'cac/loaded', '3.0', 'cac-loaded' ), |
| 114 | new Action( 'cac/inline-edit/after_ajax_column_save', '3.0', 'cacinline-editafter_ajax_column_save' ), |
| 115 | new Action( 'cac/settings/after_title', '3.0' ), |
| 116 | new Action( 'cac/settings/form_actions', '3.0' ), |
| 117 | new Action( 'cac/settings/sidebox', '3.0' ), |
| 118 | new Action( 'cac/settings/form_columns', '3.0' ), |
| 119 | new Action( 'cac/settings/after_columns', '3.0' ), |
| 120 | new Action( 'cac/column/settings_meta', '3.0' ), |
| 121 | new Action( 'cac/settings/general', '3.0' ), |
| 122 | new Action( 'cpac_messages', '3.0' ), |
| 123 | new Action( 'cac/settings/after_menu', '3.0' ), |
| 124 | new Action( 'ac/settings/general', '3.4' ), |
| 125 | ]; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * @return Hook[] |
| 130 | */ |
| 131 | public function get_deprecated_filters() { |
| 132 | return $this->check_deprecated_hooks( $this->get_filters() ); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * @return Hook[] |
| 137 | */ |
| 138 | public function get_deprecated_actions() { |
| 139 | return $this->check_deprecated_hooks( $this->get_actions() ); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * @param Hook[] $hooks |
| 144 | * |
| 145 | * @return Hook[] |
| 146 | */ |
| 147 | private function check_deprecated_hooks( $hooks ) { |
| 148 | $deprecated = []; |
| 149 | |
| 150 | foreach ( $hooks as $hook ) { |
| 151 | if ( $hook->has_hook() ) { |
| 152 | $deprecated[] = $hook; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | return $deprecated; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * @return int |
| 161 | */ |
| 162 | public function get_deprecated_count() { |
| 163 | return count( $this->get_deprecated_actions() ) + count( $this->get_deprecated_filters() ); |
| 164 | } |
| 165 | |
| 166 | } |