| @@ -2,12 +2,11 @@ | ||
| 2 | 2 | |
| 3 | 3 | if ( !class_exists( 'MeowCommon_Admin' ) ) { |
| 4 | 4 | |
| 5 | 5 | class MeowCommon_Admin { |
| 6 | - | |
| 7 | 6 | public static $loaded = false; |
| 8 | - public static $version = "4.0"; | |
| 9 | - public static $admin_version = "4.0"; | |
| 7 | + public static $version = '4.0'; | |
| 8 | + public static $admin_version = '4.0'; | |
| 10 | 9 | |
| 11 | 10 | public $prefix; // prefix used for actions, filters (mfrh) |
| 12 | 11 | public $mainfile; // plugin main file (media-file-renamer.php) |
| 13 | 12 | public $domain; // domain used for translation (media-file-renamer) |
| @@ -27,12 +26,12 @@ | ||
| 27 | 26 | // Check potential issues with this WordPress install, other plugins, etc. |
| 28 | 27 | new MeowCommon_Issues( $prefix, $mainfile, $domain ); |
| 29 | 28 | |
| 30 | 29 | // Create the Meow Apps Menu (priority 5 to ensure it's created early) |
| 31 | - add_action( 'admin_menu', array( $this, 'admin_menu_start' ), 5 ); | |
| 32 | - $page = isset( $_GET["page"] ) ? sanitize_text_field( $_GET["page"] ) : null; | |
| 30 | + add_action( 'admin_menu', [ $this, 'admin_menu_start' ], 5 ); | |
| 31 | + $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : null; | |
| 33 | 32 | if ( $page === 'meowapps-main-menu' ) { |
| 34 | - add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 100000, 1 ); | |
| 33 | + add_filter( 'admin_footer_text', [ $this, 'admin_footer_text' ], 100000, 1 ); | |
| 35 | 34 | } |
| 36 | 35 | } |
| 37 | 36 | MeowCommon_Admin::$loaded = true; |
| 38 | 37 | } |
| @@ -45,11 +44,11 @@ | ||
| 45 | 44 | |
| 46 | 45 | // If there is no mainfile, it's either a Pro only Plugin (with no Free version available) or a Theme. |
| 47 | 46 | |
| 48 | 47 | if ( is_admin() ) { |
| 49 | - $license = get_option( $this->prefix . '_license', "" ); | |
| 48 | + $license = get_option( $this->prefix . '_license', '' ); | |
| 50 | 49 | if ( !empty( $license ) && !$this->isPro ) { |
| 51 | - add_action( 'admin_notices', array( $this, 'admin_notices_licensed_free' ) ); | |
| 50 | + add_action( 'admin_notices', [ $this, 'admin_notices_licensed_free' ] ); | |
| 52 | 51 | } |
| 53 | 52 | if ( $this->is_user_admin() ) { |
| 54 | 53 | if ( !$disableReview ) { |
| 55 | 54 | new MeowCommon_Ratings( $prefix, $mainfile, $domain ); |
| @@ -56,13 +55,13 @@ | ||
| 56 | 55 | } |
| 57 | 56 | new MeowCommon_News( $domain ); |
| 58 | 57 | } |
| 59 | 58 | } |
| 60 | - add_filter( 'plugin_row_meta', array( $this, 'custom_plugin_row_meta' ), 10, 2 ); | |
| 61 | - add_filter( 'edd_sl_api_request_verify_ssl', array( $this, 'request_verify_ssl' ), 10, 0 ); | |
| 59 | + add_filter( 'plugin_row_meta', [ $this, 'custom_plugin_row_meta' ], 10, 2 ); | |
| 60 | + add_filter( 'edd_sl_api_request_verify_ssl', [ $this, 'request_verify_ssl' ], 10, 0 ); | |
| 62 | 61 | } |
| 63 | 62 | |
| 64 | - function is_user_admin() { | |
| 63 | + public function is_user_admin() { | |
| 65 | 64 | if ( !function_exists( 'current_user_can' ) || !function_exists( 'wp_get_current_user' ) ) { |
| 66 | 65 | error_log( 'MeowCommon_Admin is called too early. Please make sure it is called after the plugins_loaded filter.' ); |
| 67 | 66 | return false; |
| 68 | 67 | } |
| @@ -68,9 +67,9 @@ | ||
| 68 | 67 | } |
| 69 | 68 | return current_user_can( 'manage_options' ); |
| 70 | 69 | } |
| 71 | 70 | |
| 72 | - function custom_plugin_row_meta( $links, $file ) { | |
| 71 | + public function custom_plugin_row_meta( $links, $file ) { | |
| 73 | 72 | $path = pathinfo( $file ); |
| 74 | 73 | $pathName = basename( $path['dirname'] ); |
| 75 | 74 | $thisPath = pathinfo( $this->mainfile ); |
| 76 | 75 | $thisPathName = basename( $thisPath['dirname'] ); |
| @@ -79,30 +78,30 @@ | ||
| 79 | 78 | return $links; |
| 80 | 79 | } |
| 81 | 80 | $isIssue = $this->isPro && !$this->is_registered(); |
| 82 | 81 | if ( strpos( $pathName, $thisPathName ) !== false ) { |
| 83 | - $new_links = array( | |
| 84 | - 'settings' => | |
| 85 | - sprintf( __( '<a href="admin.php?page=%s_settings">Settings</a>', $this->domain ), $this->prefix ), | |
| 86 | - 'license' => | |
| 87 | - $this->is_registered() ? | |
| 88 | - ('<span style="color: #a75bd6;">' . __( 'Pro Version', $this->domain ) . '</span>') : | |
| 89 | - ( $isIssue ? (sprintf( '<span style="color: #ff3434;">' . __( 'License Issue', $this->domain ), $this->prefix ) . '</span>') : (sprintf( '<span>' . __( '<a target="_blank" href="https://meowapps.com">Get the <u>Pro Version</u></a>', $this->domain ), $this->prefix ) . '</span>') ), | |
| 90 | - ); | |
| 82 | + $new_links = [ | |
| 83 | + 'settings' => | |
| 84 | + sprintf( __( '<a href="admin.php?page=%s_settings">Settings</a>', $this->domain ), $this->prefix ), | |
| 85 | + 'license' => | |
| 86 | + $this->is_registered() ? | |
| 87 | + ( '<span style="color: #a75bd6;">' . __( 'Pro Version', $this->domain ) . '</span>' ) : | |
| 88 | + ( $isIssue ? ( sprintf( '<span style="color: #ff3434;">' . __( 'License Issue', $this->domain ), $this->prefix ) . '</span>' ) : ( sprintf( '<span>' . __( '<a target="_blank" href="https://meowapps.com">Get the <u>Pro Version</u></a>', $this->domain ), $this->prefix ) . '</span>' ) ), | |
| 89 | + ]; | |
| 91 | 90 | $links = array_merge( $new_links, $links ); |
| 92 | 91 | } |
| 93 | 92 | return $links; |
| 94 | 93 | } |
| 95 | 94 | |
| 96 | - function request_verify_ssl() { | |
| 95 | + public function request_verify_ssl() { | |
| 97 | 96 | return get_option( 'force_sslverify', false ); |
| 98 | 97 | } |
| 99 | 98 | |
| 100 | - function nice_name_from_file( $file ) { | |
| 99 | + public function nice_name_from_file( $file ) { | |
| 101 | 100 | $info = pathinfo( $file ); |
| 102 | 101 | if ( !empty( $info ) ) { |
| 103 | 102 | if ( $info['filename'] == 'wplr-sync' ) { |
| 104 | - return "WP/LR Sync"; | |
| 103 | + return 'WP/LR Sync'; | |
| 105 | 104 | } |
| 106 | 105 | $info['filename'] = str_replace( '-', ' ', $info['filename'] ); |
| 107 | 106 | $file = ucwords( $info['filename'] ); |
| 108 | 107 | } |
| @@ -108,9 +107,9 @@ | ||
| 108 | 107 | } |
| 109 | 108 | return $file; |
| 110 | 109 | } |
| 111 | 110 | |
| 112 | - function admin_notices_licensed_free() { | |
| 111 | + public function admin_notices_licensed_free() { | |
| 113 | 112 | if ( isset( $_POST[$this->prefix . '_reset_sub'] ) ) { |
| 114 | 113 | delete_option( $this->prefix . '_pro_serial' ); |
| 115 | 114 | delete_option( $this->prefix . '_license' ); |
| 116 | 115 | return; |
| @@ -117,25 +116,26 @@ | ||
| 117 | 116 | } |
| 118 | 117 | $html = '<div class="notice notice-error">'; |
| 119 | 118 | $html .= sprintf( |
| 120 | 119 | __( '<p>It looks like you are using the free version of the plugin (<b>%s</b>) but a license for the Pro version was also found. The Pro version might have been replaced by the Free version during an update (might be caused by a temporarily issue). If it is the case, <b>please download it again</b> from the <a target="_blank" href="https://meowapps.com">Meow Store</a>. If you wish to continue using the free version and clear this message, click on this button.', $this->domain ), |
| 121 | - $this->nice_name_from_file( $this->mainfile ) ); | |
| 122 | - $html .= '<p> | |
| 123 | - <form method="post" action=""> | |
| 124 | - <input type="hidden" name="' . $this->prefix . '_reset_sub" value="true"> | |
| 125 | - <input type="submit" name="submit" id="submit" class="button" value="' | |
| 126 | - . __( 'Remove the license', $this->domain ) . '"> | |
| 127 | - </form> | |
| 128 | - </p>'; | |
| 120 | + $this->nice_name_from_file( $this->mainfile ) | |
| 121 | + ); | |
| 122 | + $html .= '<p> | |
| 123 | + <form method="post" action=""> | |
| 124 | + <input type="hidden" name="' . $this->prefix . '_reset_sub" value="true"> | |
| 125 | + <input type="submit" name="submit" id="submit" class="button" value="' | |
| 126 | + . __( 'Remove the license', $this->domain ) . '"> | |
| 127 | + </form> | |
| 128 | + </p>'; | |
| 129 | 129 | $html .= '</div>'; |
| 130 | 130 | wp_kses_post( $html ); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - function admin_menu_start() { | |
| 133 | + public function admin_menu_start() { | |
| 134 | 134 | // Hide the admin if user doesn't like Meow much |
| 135 | 135 | if ( get_option( 'meowapps_hide_meowapps', false ) ) { |
| 136 | 136 | register_setting( 'general', 'meowapps_hide_meowapps' ); |
| 137 | - add_settings_field( 'meowapps_hide_ads', 'Meow Apps Menu', array( $this, 'meowapps_hide_dashboard_callback' ), 'general' ); | |
| 137 | + add_settings_field( 'meowapps_hide_ads', 'Meow Apps Menu', [ $this, 'meowapps_hide_dashboard_callback' ], 'general' ); | |
| 138 | 138 | return; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | // Create standard menu if it does not already exist |
| @@ -140,38 +140,50 @@ | ||
| 140 | 140 | |
| 141 | 141 | // Create standard menu if it does not already exist |
| 142 | 142 | global $submenu; |
| 143 | 143 | if ( !isset( $submenu[ 'meowapps-main-menu' ] ) ) { |
| 144 | - add_menu_page( 'Meow Apps', '<img alt="Meow Apps" style="width: 22px; margin-left: -30px; position: absolute; margin-top: -0px;" src="' . MeowCommon_Admin::$logo . '" />Meow Apps', 'manage_options', 'meowapps-main-menu', | |
| 145 | - array( $this, 'admin_meow_apps' ), '', 82 ); | |
| 146 | - add_submenu_page( 'meowapps-main-menu', __( 'Dashboard', $this->domain ), | |
| 147 | - __( 'Dashboard', $this->domain ), 'manage_options', | |
| 148 | - 'meowapps-main-menu', array( $this, 'admin_meow_apps' ) ); | |
| 144 | + add_menu_page( | |
| 145 | + 'Meow Apps', | |
| 146 | + '<img alt="Meow Apps" style="width: 22px; margin-left: -30px; position: absolute; margin-top: -0px;" src="' . MeowCommon_Admin::$logo . '" />Meow Apps', | |
| 147 | + 'manage_options', | |
| 148 | + 'meowapps-main-menu', | |
| 149 | + [ $this, 'admin_meow_apps' ], | |
| 150 | + '', | |
| 151 | + 82 | |
| 152 | + ); | |
| 153 | + add_submenu_page( | |
| 154 | + 'meowapps-main-menu', | |
| 155 | + __( 'Dashboard', $this->domain ), | |
| 156 | + __( 'Dashboard', $this->domain ), | |
| 157 | + 'manage_options', | |
| 158 | + 'meowapps-main-menu', | |
| 159 | + [ $this, 'admin_meow_apps' ] | |
| 160 | + ); | |
| 149 | 161 | } |
| 150 | 162 | |
| 151 | 163 | // Add CSS to hide the default icon |
| 152 | - add_action( 'admin_head', function() { | |
| 164 | + add_action( 'admin_head', function () { | |
| 153 | 165 | echo '<style> |
| 154 | - #toplevel_page_meowapps-main-menu .wp-menu-image { | |
| 155 | - display: none; | |
| 156 | - } | |
| 157 | - </style>'; | |
| 158 | - }); | |
| 166 | + #toplevel_page_meowapps-main-menu .wp-menu-image { | |
| 167 | + display: none; | |
| 168 | + } | |
| 169 | + </style>'; | |
| 170 | + } ); | |
| 159 | 171 | } |
| 160 | 172 | |
| 161 | - function meowapps_hide_dashboard_callback() { | |
| 173 | + public function meowapps_hide_dashboard_callback() { | |
| 162 | 174 | $html = '<input type="checkbox" id="meowapps_hide_meowapps" name="meowapps_hide_meowapps" value="1" ' . |
| 163 | - checked( 1, get_option( 'meowapps_hide_meowapps' ), false ) . '/>'; | |
| 175 | + checked( 1, get_option( 'meowapps_hide_meowapps' ), false ) . '/>'; | |
| 164 | 176 | $html .= __( '<label>Hide <b>Meow Apps</b> Menu</label><br /><small>Hide Meow Apps menu and all its components, for a cleaner admin. This option will be reset if a new Meow Apps plugin is installed.<br /><b>Once activated, an option will be added in your General settings to display it again.</b></small>', $this->domain ); |
| 165 | 177 | echo MeowCommon_Helpers::wp_kses( $html ); |
| 166 | 178 | } |
| 167 | 179 | |
| 168 | - function is_registered() { | |
| 180 | + public function is_registered() { | |
| 169 | 181 | $is_registered = apply_filters( $this->prefix . '_meowapps_is_registered', false, $this->prefix ); |
| 170 | 182 | return $is_registered; |
| 171 | 183 | } |
| 172 | 184 | |
| 173 | - function get_phpinfo() { | |
| 185 | + public function get_phpinfo() { | |
| 174 | 186 | if ( !$this->is_user_admin() || !function_exists( 'phpinfo' ) ) { |
| 175 | 187 | return; |
| 176 | 188 | } |
| 177 | 189 | ob_start(); |
| @@ -179,22 +191,22 @@ | ||
| 179 | 191 | phpinfo( INFO_GENERAL | INFO_CONFIGURATION | INFO_MODULES ); |
| 180 | 192 | // phpcs:enable |
| 181 | 193 | $html = ob_get_contents(); |
| 182 | 194 | ob_end_clean(); |
| 183 | - $html = preg_replace( '%^.*<body>(.*)</body>.*$%ms','$1', $html ); | |
| 195 | + $html = preg_replace( '%^.*<body>(.*)</body>.*$%ms', '$1', $html ); | |
| 184 | 196 | return $html; |
| 185 | 197 | } |
| 186 | - | |
| 187 | - function admin_meow_apps() { | |
| 198 | + | |
| 199 | + public function admin_meow_apps() { | |
| 188 | 200 | $html = "<div id='meow-common-dashboard'></div>"; |
| 189 | 201 | $html .= "<div style='height: 0; width: 0; overflow: hidden;' id='meow-common-phpinfo'>"; |
| 190 | - $html .= $this->get_phpinfo(); | |
| 191 | - $html .= "</div>"; | |
| 192 | - $html = preg_replace("/<img[^>]+\>/i", "", $html); | |
| 202 | + $html .= $this->get_phpinfo(); | |
| 203 | + $html .= '</div>'; | |
| 204 | + $html = preg_replace( "/<img[^>]+\>/i", '', $html ); | |
| 193 | 205 | echo wp_kses_post( $html ); |
| 194 | 206 | } |
| 195 | 207 | |
| 196 | - function admin_footer_text( $current ) { | |
| 208 | + public function admin_footer_text( $current ) { | |
| 197 | 209 | return sprintf( |
| 198 | 210 | // translators: %1$s is the version of the interface; %2$s is a file path. |
| 199 | 211 | __( 'Thanks for using <a href="https://meowapps.com">Meow Apps</a>! This is the Meow Admin %1$s <br /><i>Loaded from %2$s </i>', $this->domain ), |
| 200 | 212 | MeowCommon_Admin::$version, |
| @@ -202,5 +214,4 @@ | ||
| 202 | 214 | ); |
| 203 | 215 | } |
| 204 | 216 | } |
| 205 | 217 | } |
| 206 | -?> | |