Help.php
160 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Admin\Main; |
| 4 | |
| 5 | use AC; |
| 6 | use AC\Asset\Assets; |
| 7 | use AC\Asset\Enqueueables; |
| 8 | use AC\Asset\Location; |
| 9 | use AC\Asset\Style; |
| 10 | use AC\Deprecated\Hooks; |
| 11 | use AC\Renderable; |
| 12 | use AC\Type\Url; |
| 13 | |
| 14 | class Help implements Enqueueables, Renderable { |
| 15 | |
| 16 | const NAME = 'help'; |
| 17 | |
| 18 | /** @var Hooks */ |
| 19 | private $hooks; |
| 20 | |
| 21 | /** |
| 22 | * @var Location\Absolute |
| 23 | */ |
| 24 | private $location; |
| 25 | |
| 26 | public function __construct( Hooks $hooks, Location\Absolute $location ) { |
| 27 | $this->hooks = $hooks; |
| 28 | $this->location = $location; |
| 29 | } |
| 30 | |
| 31 | public function get_assets() { |
| 32 | return new Assets( [ |
| 33 | new Style( 'ac-admin-page-help-css', $this->location->with_suffix( 'assets/css/admin-page-help.css' ) ), |
| 34 | ] ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @return string |
| 39 | */ |
| 40 | private function get_documention_link() { |
| 41 | return sprintf( |
| 42 | '<a href="%s" target="_blank">%s »</a>', |
| 43 | ( new Url\Documentation( Url\Documentation::ARTICLE_UPGRADE_V3_TO_V4 ) )->get_url(), |
| 44 | __( 'View documentation', 'codepress-admin-columns' ) |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @param array $callbacks |
| 50 | * |
| 51 | * @return false|string |
| 52 | */ |
| 53 | private function get_callback_message( $callbacks ) { |
| 54 | if ( ! $callbacks ) { |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | return sprintf( _n( 'The callback used is %s.', 'The callbacks used are %s.', count( $callbacks ), 'codepress-admin-columns' ), '<code>' . implode( '</code>, <code>', $callbacks ) . '</code>' ); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @return void |
| 63 | */ |
| 64 | private function render_actions() { |
| 65 | $hooks = $this->hooks->get_deprecated_actions(); |
| 66 | |
| 67 | if ( ! $hooks ) { |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | ?> |
| 72 | <h3><?php __( 'Deprecated Actions', 'codepress-admin-columns' ); ?></h3> |
| 73 | <?php |
| 74 | |
| 75 | foreach ( $hooks as $hook ) { |
| 76 | $message = sprintf( __( 'The action %s used on this website is deprecated since %s.', 'codepress-admin-columns' ), '<code>' . $hook->get_name() . '</code>', '<strong>' . $hook->get_version() . '</strong>' ); |
| 77 | |
| 78 | $callbacks = $hook->get_callbacks(); |
| 79 | |
| 80 | if ( $callbacks ) { |
| 81 | $message .= ' ' . $this->get_callback_message( $callbacks ); |
| 82 | } |
| 83 | |
| 84 | $message .= ' ' . $this->get_documention_link(); |
| 85 | |
| 86 | $this->render_message( $message ); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @return void |
| 92 | */ |
| 93 | private function render_filters() { |
| 94 | $hooks = $this->hooks->get_deprecated_filters(); |
| 95 | |
| 96 | if ( ! $hooks ) { |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | ?> |
| 101 | <h3><?php __( 'Deprecated Filters', 'codepress-admin-columns' ); ?></h3> |
| 102 | <?php |
| 103 | |
| 104 | foreach ( $hooks as $hook ) { |
| 105 | $message = sprintf( __( 'The filter %s used on this website is deprecated since %s.', 'codepress-admin-columns' ), '<code>' . $hook->get_name() . '</code>', '<strong>' . $hook->get_version() . '</strong>' ); |
| 106 | |
| 107 | $callbacks = $hook->get_callbacks(); |
| 108 | |
| 109 | if ( $callbacks ) { |
| 110 | $message .= ' ' . $this->get_callback_message( $callbacks ); |
| 111 | } |
| 112 | |
| 113 | $message .= ' ' . $this->get_documention_link(); |
| 114 | |
| 115 | $this->render_message( $message ); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | private function render_message( $message ) { |
| 120 | ?> |
| 121 | <div class="ac-deprecated-message"> |
| 122 | <p><?php echo $message; ?></p> |
| 123 | </div> |
| 124 | <?php |
| 125 | } |
| 126 | |
| 127 | public function render() { |
| 128 | // Force cache refresh |
| 129 | $this->hooks->get_count( true ); |
| 130 | |
| 131 | ob_start(); |
| 132 | ?> |
| 133 | <h2><?php _e( 'Help', 'codepress-admin-columns' ); ?></h2> |
| 134 | <p> |
| 135 | <?php _e( 'The Admin Columns plugin has undergone some major changes in version 4.', 'codepress-admin-columns' ); ?> <br/> |
| 136 | |
| 137 | <?php |
| 138 | printf( |
| 139 | __( 'This site is using some actions or filters that have changed. Please read %s to resolve them.', 'codepress-admin-columns' ), |
| 140 | sprintf( |
| 141 | '<a href="%s" target="_blank">%s</a>', ( new Url\Documentation( Url\Documentation::ARTICLE_UPGRADE_V3_TO_V4 ) )->get_url(), |
| 142 | __( 'our documentation', 'codepress-admin-columns' ) |
| 143 | ) |
| 144 | ); |
| 145 | ?> |
| 146 | </p> |
| 147 | |
| 148 | <?php |
| 149 | |
| 150 | if ( $this->hooks->get_count() > 0 ) { |
| 151 | $this->render_actions(); |
| 152 | $this->render_filters(); |
| 153 | } else { |
| 154 | printf( '<em>%s</em>', __( 'No deprecated hooks or filters found.', 'codepress-admin-columns' ) ); |
| 155 | } |
| 156 | |
| 157 | return ob_get_clean(); |
| 158 | } |
| 159 | |
| 160 | } |