| @@ -2,11 +2,12 @@ | ||
| 2 | 2 | |
| 3 | 3 | if ( !class_exists( 'MeowCommon_Admin' ) ) { |
| 4 | 4 | |
| 5 | 5 | class MeowCommon_Admin { |
| 6 | + | |
| 6 | 7 | public static $loaded = false; |
| 7 | - public static $version = '4.0'; | |
| 8 | - public static $admin_version = '4.0'; | |
| 8 | + public static $version = "4.0"; | |
| 9 | + public static $admin_version = "4.0"; | |
| 9 | 10 | |
| 10 | 11 | public $prefix; // prefix used for actions, filters (mfrh) |
| 11 | 12 | public $mainfile; // plugin main file (media-file-renamer.php) |
| 12 | 13 | public $domain; // domain used for translation (media-file-renamer) |
| @@ -25,13 +26,13 @@ | ||
| 25 | 26 | |
| 26 | 27 | // Check potential issues with this WordPress install, other plugins, etc. |
| 27 | 28 | new MeowCommon_Issues( $prefix, $mainfile, $domain ); |
| 28 | 29 | |
| 29 | - // Create the Meow Apps Menu (priority 5 to ensure it's created early) | |
| 30 | - add_action( 'admin_menu', [ $this, 'admin_menu_start' ], 5 ); | |
| 31 | - $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : null; | |
| 30 | + // Create the Meow Apps Menu | |
| 31 | + add_action( 'admin_menu', array( $this, 'admin_menu_start' ) ); | |
| 32 | + $page = isset( $_GET["page"] ) ? sanitize_text_field( $_GET["page"] ) : null; | |
| 32 | 33 | if ( $page === 'meowapps-main-menu' ) { |
| 33 | - add_filter( 'admin_footer_text', [ $this, 'admin_footer_text' ], 100000, 1 ); | |
| 34 | + add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 100000, 1 ); | |
| 34 | 35 | } |
| 35 | 36 | } |
| 36 | 37 | MeowCommon_Admin::$loaded = true; |
| 37 | 38 | } |
| @@ -44,11 +45,11 @@ | ||
| 44 | 45 | |
| 45 | 46 | // If there is no mainfile, it's either a Pro only Plugin (with no Free version available) or a Theme. |
| 46 | 47 | |
| 47 | 48 | if ( is_admin() ) { |
| 48 | - $license = get_option( $this->prefix . '_license', '' ); | |
| 49 | + $license = get_option( $this->prefix . '_license', "" ); | |
| 49 | 50 | if ( !empty( $license ) && !$this->isPro ) { |
| 50 | - add_action( 'admin_notices', [ $this, 'admin_notices_licensed_free' ] ); | |
| 51 | + add_action( 'admin_notices', array( $this, 'admin_notices_licensed_free' ) ); | |
| 51 | 52 | } |
| 52 | 53 | if ( $this->is_user_admin() ) { |
| 53 | 54 | if ( !$disableReview ) { |
| 54 | 55 | new MeowCommon_Ratings( $prefix, $mainfile, $domain ); |
| @@ -55,13 +56,13 @@ | ||
| 55 | 56 | } |
| 56 | 57 | new MeowCommon_News( $domain ); |
| 57 | 58 | } |
| 58 | 59 | } |
| 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 ); | |
| 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 ); | |
| 61 | 62 | } |
| 62 | 63 | |
| 63 | - public function is_user_admin() { | |
| 64 | + function is_user_admin() { | |
| 64 | 65 | if ( !function_exists( 'current_user_can' ) || !function_exists( 'wp_get_current_user' ) ) { |
| 65 | 66 | error_log( 'MeowCommon_Admin is called too early. Please make sure it is called after the plugins_loaded filter.' ); |
| 66 | 67 | return false; |
| 67 | 68 | } |
| @@ -67,9 +68,9 @@ | ||
| 67 | 68 | } |
| 68 | 69 | return current_user_can( 'manage_options' ); |
| 69 | 70 | } |
| 70 | 71 | |
| 71 | - public function custom_plugin_row_meta( $links, $file ) { | |
| 72 | + function custom_plugin_row_meta( $links, $file ) { | |
| 72 | 73 | $path = pathinfo( $file ); |
| 73 | 74 | $pathName = basename( $path['dirname'] ); |
| 74 | 75 | $thisPath = pathinfo( $this->mainfile ); |
| 75 | 76 | $thisPathName = basename( $thisPath['dirname'] ); |
| @@ -78,30 +79,30 @@ | ||
| 78 | 79 | return $links; |
| 79 | 80 | } |
| 80 | 81 | $isIssue = $this->isPro && !$this->is_registered(); |
| 81 | 82 | if ( strpos( $pathName, $thisPathName ) !== false ) { |
| 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 | - ]; | |
| 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 | + ); | |
| 90 | 91 | $links = array_merge( $new_links, $links ); |
| 91 | 92 | } |
| 92 | 93 | return $links; |
| 93 | 94 | } |
| 94 | 95 | |
| 95 | - public function request_verify_ssl() { | |
| 96 | + function request_verify_ssl() { | |
| 96 | 97 | return get_option( 'force_sslverify', false ); |
| 97 | 98 | } |
| 98 | 99 | |
| 99 | - public function nice_name_from_file( $file ) { | |
| 100 | + function nice_name_from_file( $file ) { | |
| 100 | 101 | $info = pathinfo( $file ); |
| 101 | 102 | if ( !empty( $info ) ) { |
| 102 | 103 | if ( $info['filename'] == 'wplr-sync' ) { |
| 103 | - return 'WP/LR Sync'; | |
| 104 | + return "WP/LR Sync"; | |
| 104 | 105 | } |
| 105 | 106 | $info['filename'] = str_replace( '-', ' ', $info['filename'] ); |
| 106 | 107 | $file = ucwords( $info['filename'] ); |
| 107 | 108 | } |
| @@ -107,9 +108,9 @@ | ||
| 107 | 108 | } |
| 108 | 109 | return $file; |
| 109 | 110 | } |
| 110 | 111 | |
| 111 | - public function admin_notices_licensed_free() { | |
| 112 | + function admin_notices_licensed_free() { | |
| 112 | 113 | if ( isset( $_POST[$this->prefix . '_reset_sub'] ) ) { |
| 113 | 114 | delete_option( $this->prefix . '_pro_serial' ); |
| 114 | 115 | delete_option( $this->prefix . '_license' ); |
| 115 | 116 | return; |
| @@ -116,26 +117,25 @@ | ||
| 116 | 117 | } |
| 117 | 118 | $html = '<div class="notice notice-error">'; |
| 118 | 119 | $html .= sprintf( |
| 119 | 120 | __( '<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 ), |
| 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>'; | |
| 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>'; | |
| 129 | 129 | $html .= '</div>'; |
| 130 | 130 | wp_kses_post( $html ); |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - public function admin_menu_start() { | |
| 133 | + 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', [ $this, 'meowapps_hide_dashboard_callback' ], 'general' ); | |
| 137 | + add_settings_field( 'meowapps_hide_ads', 'Meow Apps Menu', array( $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,50 +140,38 @@ | ||
| 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( | |
| 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 | - ); | |
| 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' ) ); | |
| 161 | 149 | } |
| 162 | 150 | |
| 163 | 151 | // Add CSS to hide the default icon |
| 164 | - add_action( 'admin_head', function () { | |
| 152 | + add_action( 'admin_head', function() { | |
| 165 | 153 | echo '<style> |
| 166 | - #toplevel_page_meowapps-main-menu .wp-menu-image { | |
| 167 | - display: none; | |
| 168 | - } | |
| 169 | - </style>'; | |
| 170 | - } ); | |
| 154 | + #toplevel_page_meowapps-main-menu .wp-menu-image { | |
| 155 | + display: none; | |
| 156 | + } | |
| 157 | + </style>'; | |
| 158 | + }); | |
| 171 | 159 | } |
| 172 | 160 | |
| 173 | - public function meowapps_hide_dashboard_callback() { | |
| 161 | + function meowapps_hide_dashboard_callback() { | |
| 174 | 162 | $html = '<input type="checkbox" id="meowapps_hide_meowapps" name="meowapps_hide_meowapps" value="1" ' . |
| 175 | - checked( 1, get_option( 'meowapps_hide_meowapps' ), false ) . '/>'; | |
| 163 | + checked( 1, get_option( 'meowapps_hide_meowapps' ), false ) . '/>'; | |
| 176 | 164 | $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 ); |
| 177 | 165 | echo MeowCommon_Helpers::wp_kses( $html ); |
| 178 | 166 | } |
| 179 | 167 | |
| 180 | - public function is_registered() { | |
| 168 | + function is_registered() { | |
| 181 | 169 | $is_registered = apply_filters( $this->prefix . '_meowapps_is_registered', false, $this->prefix ); |
| 182 | 170 | return $is_registered; |
| 183 | 171 | } |
| 184 | 172 | |
| 185 | - public function get_phpinfo() { | |
| 173 | + function get_phpinfo() { | |
| 186 | 174 | if ( !$this->is_user_admin() || !function_exists( 'phpinfo' ) ) { |
| 187 | 175 | return; |
| 188 | 176 | } |
| 189 | 177 | ob_start(); |
| @@ -191,22 +179,22 @@ | ||
| 191 | 179 | phpinfo( INFO_GENERAL | INFO_CONFIGURATION | INFO_MODULES ); |
| 192 | 180 | // phpcs:enable |
| 193 | 181 | $html = ob_get_contents(); |
| 194 | 182 | ob_end_clean(); |
| 195 | - $html = preg_replace( '%^.*<body>(.*)</body>.*$%ms', '$1', $html ); | |
| 183 | + $html = preg_replace( '%^.*<body>(.*)</body>.*$%ms','$1', $html ); | |
| 196 | 184 | return $html; |
| 197 | 185 | } |
| 198 | - | |
| 199 | - public function admin_meow_apps() { | |
| 186 | + | |
| 187 | + function admin_meow_apps() { | |
| 200 | 188 | $html = "<div id='meow-common-dashboard'></div>"; |
| 201 | 189 | $html .= "<div style='height: 0; width: 0; overflow: hidden;' id='meow-common-phpinfo'>"; |
| 202 | - $html .= $this->get_phpinfo(); | |
| 203 | - $html .= '</div>'; | |
| 204 | - $html = preg_replace( "/<img[^>]+\>/i", '', $html ); | |
| 190 | + $html .= $this->get_phpinfo(); | |
| 191 | + $html .= "</div>"; | |
| 192 | + $html = preg_replace("/<img[^>]+\>/i", "", $html); | |
| 205 | 193 | echo wp_kses_post( $html ); |
| 206 | 194 | } |
| 207 | 195 | |
| 208 | - public function admin_footer_text( $current ) { | |
| 196 | + function admin_footer_text( $current ) { | |
| 209 | 197 | return sprintf( |
| 210 | 198 | // translators: %1$s is the version of the interface; %2$s is a file path. |
| 211 | 199 | __( '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 ), |
| 212 | 200 | MeowCommon_Admin::$version, |
| @@ -214,4 +202,5 @@ | ||
| 214 | 202 | ); |
| 215 | 203 | } |
| 216 | 204 | } |
| 217 | 205 | } |
| 206 | +?> | |