PluginProbe
Show IDs by Echo / trunk
Show IDs by Echo vtrunk
1.3.4 trunk 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3
echo-show-ids / echo-show-ids.php

echo-show-ids.php in Show IDs by Echo trunk, at echo-show-ids.php

238 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Show IDs by Echo
4 * Plugin URI: http://www.echoplugins.com
5 * Description: Show IDs on admin pages for posts, pages, categories, taxonomies, custom post types and more.
6 * Version: 1.3.4
7 * Author: Echo Plugins
8 * Author URI: http://www.echoplugins.com
9 * License: GNU General Public License v2.0
10 * License URI: http://www.gnu.org/licenses/gpl-2.0.html
11 *
12 * Show IDs by Echo Plugins is distributed under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or
14 * any later version.
15 *
16 * Show IDs by Echo Plugins is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with Show IDs by Echo Plugins. If not, see <http://www.gnu.org/licenses/>.
23 *
24 */
25
26 if ( ! defined( 'ABSPATH' ) ) exit;
27
28
29 /**
30 * Main class to load the plugin.
31 *
32 * Singleton
33 */
34 final class Echo_Show_IDs {
35
36 /* @var Echo_Show_IDs */
37 private static $instance;
38
39 public static $version = '1.3.4';
40 public static $plugin_dir;
41 public static $plugin_url;
42 public static $plugin_file = __FILE__;
43
44 /* @var EPSI_Settings_DB */
45 public $settings;
46
47 /**
48 * Initialise the plugin
49 */
50 private function __construct() {
51 self::$plugin_dir = plugin_dir_path( __FILE__ );
52 self::$plugin_url = plugin_dir_url( __FILE__ );
53 }
54
55 /**
56 * Retrieve or create a new instance of this main class (avoid global vars)
57 *
58 * @static
59 * @return Echo_Show_IDs
60 */
61 public static function instance() {
62
63 if ( ! empty( self::$instance ) && ( self::$instance instanceof Echo_Show_IDs ) ) {
64 return self::$instance;
65 }
66
67 self::$instance = new Echo_Show_IDs();
68
69 self::$instance->includes();
70 self::$instance->setup_system();
71 self::$instance->setup_plugin();
72
73 return self::$instance;
74 }
75
76 private function includes() {
77 if ( is_admin() ) {
78 require_once $this::$plugin_dir . 'includes/class-epsi-show-ids.php';
79 require_once $this::$plugin_dir . 'includes/class-epsi-input-filter.php';
80 require_once $this::$plugin_dir . 'includes/class-epsi-html-elements.php';
81 require_once self::$plugin_dir . 'includes/admin/features-settings/features-settings-page.php';
82 require_once $this::$plugin_dir . 'includes/admin/features-settings/class-epsi-settings-controller.php';
83 require_once $this::$plugin_dir . 'includes/admin/features-settings/class-epsi-settings-db.php';
84 require_once $this::$plugin_dir . 'includes/admin/features-settings/class-epsi-settings-specs.php';
85 }
86 }
87
88 /**
89 * Setup class autoloading and other support functions
90 */
91 private function setup_system() {
92 if ( is_admin() ) {
93 self::$instance->settings = new EPSI_Settings_DB();
94 }
95 }
96
97 /**
98 * Setup plugin before it runs i.e. ensure settings have (default) values etc.
99 */
100 private function setup_plugin() {
101
102 // plugin setup is based on whether we are serving the front-end or the back-end
103
104 // 1) IF is admin or CLI or AJAX front-end request (from any user) then load related files
105 if ( is_admin() ) {
106
107 // only when on admin page - initialize hook for saving config and settings
108 // phpcs:disable WordPress.Security.NonceVerification.Recommended
109 if ( ! empty( $_REQUEST['action']) && !strncmp( $_REQUEST['action'], 'epsi_', strlen('epsi_') ) ) {
110 new EPSI_Settings_Controller();
111 }
112
113 new EPSI_Show_IDs();
114 }
115 }
116
117 // Don't allow this singleton to be cloned.
118 public function __clone() {
119 _doing_it_wrong( __FUNCTION__, 'Invalid (#1)', '4.0' );
120 }
121
122 // Don't allow un-serializing of the class except when testing
123 public function __wakeup() {
124 if ( strpos($GLOBALS['argv'][0], 'phpunit') === false ) {
125 _doing_it_wrong( __FUNCTION__, 'Invalid (#1)', '4.0' );
126 }
127 }
128 }
129
130 /**
131 * Returns the single instance of this class
132 *
133 * @return object - this class instance
134 */
135 function epsi_get_instance() {
136 return Echo_Show_IDs::instance();
137 }
138 epsi_get_instance();
139
140
141 /**
142 * Adds various links for plugin on the Plugins page displayed on the left
143 *
144 * @param array $links contains current links for this plugin
145 * @return array returns an array of links
146 */
147 function epsi_add_plugin_action_links ( $links ) {
148
149 $my_links = array(
150 'Settings' => '<a href="' . admin_url('options-general.php?page=show-ids-settings') . '">'. __( 'Settings' ) . '</a>',
151 'Support' => '<a href="https://www.echoknowledgebase.com/contact-us/" target="_blank">' . __( 'Support' ) . '</a>'
152 );
153
154 return array_merge( $my_links, $links );
155 }
156 add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'epsi_add_plugin_action_links', 10, 2 );
157
158 /**
159 * Register plugin options as a sub-menu for WordPress Settings menu
160 */
161 function epsi_add_plugin_menus() {
162
163 $feature_settings_page = add_options_page( esc_html__( 'Show IDs', 'echo-show-ids' ), esc_html__( 'Show IDs', 'echo-show-ids' ), 'manage_options', 'show-ids-settings', 'epsi_display_features_settings_page' );
164 if ( $feature_settings_page === false ) {
165 return;
166 }
167
168 // Register (i.e. whitelist) the option for the configuration pages.
169 register_setting('epsi_settings', 'epsi_settings');
170
171 // load scripts needed for Features Settings page only on that page
172 add_action( 'load-' . $feature_settings_page, 'epsi_load_admin_page_resources' );
173 }
174 add_action('admin_menu', 'epsi_add_plugin_menus' );
175
176 function epsi_load_admin_page_resources() {
177 add_action( 'admin_enqueue_scripts', 'epsi_load_admin_pages_resources' );
178 }
179
180 function epsi_load_admin_pages_resources( ) {
181
182 // if SCRIPT_DEBUG is off then use minified scripts
183 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
184 wp_enqueue_script('epsi-admin-bar-scripts', Echo_Show_IDs::$plugin_url . 'js/admin-pages' . $suffix . '.js', array( 'jquery', 'jquery-ui-core','jquery-ui-dialog','jquery-effects-core' ), Echo_Show_IDs::$version );
185 wp_enqueue_style('epsi-admin-pages-styles', Echo_Show_IDs::$plugin_url . 'css/admin-pages' . $suffix . '.css', array(), Echo_Show_IDs::$version );
186 wp_enqueue_style( 'wp-jquery-ui-dialog' );
187 }
188 function epsi_load_admin_feature_resources( ) {
189 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
190 wp_enqueue_style('epsi-admin-feature-styles', Echo_Show_IDs::$plugin_url . 'css/admin-features' . $suffix . '.css', array(), Echo_Show_IDs::$version );
191
192 }
193 add_action( 'admin_enqueue_scripts', 'epsi_load_admin_feature_resources' );
194
195 /**
196 * Show noticers for admin at the top of the page
197 */
198 function epsi_show_admin_notices() {
199
200 // phpcs:disable WordPress.Security.NonceVerification.Recommended
201 $admin_notice = empty( $_GET['epsi_admin_notice'] ) ? '' : $_GET['epsi_admin_notice'];
202 if ( empty( $admin_notice ) ) {
203 return;
204 }
205
206 $type = 'error';
207 switch ( $admin_notice ) {
208
209 case 'ep_settings_saved' :
210 $message = esc_html__( 'Settings saved', 'echo-show-ids' );
211 $type = 'success';
212 break;
213 case 'ep_refresh_page' :
214 $message = esc_html__( 'Refresh your page', 'echo-show-ids' );
215 break;
216 case 'ep_refresh_page_error' :
217 $message = esc_html__( 'Error occurred. Please refresh your browser and try again', 'echo-show-ids' );
218 break;
219 case 'ep_security_failed' :
220 $message = esc_html__( 'You do not have permission', 'echo-show-ids' );
221 break;
222 default:
223 $message = esc_html__( 'unknown error', 'echo-show-ids' ) . ' (1223)';
224 break;
225 }
226
227 echo
228 "<div id='epsi-top-notice-message'>
229 <div class='epsi_notification'>
230 <span class='$type'>
231 <!--<h4>title</h4> -->
232 <p>$message</p>
233 </span>
234 </div>
235 </div>";
236 }
237 add_action( 'admin_notices', 'epsi_show_admin_notices' );
238