PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.44
Code Manager v1.0.44
1.0.47 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.38 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9
code-manager / code-manager.php
code-manager Last commit date
Code_Manager 9 months ago admin 9 months ago assets 9 months ago includes 9 months ago public 9 months ago vendor 9 months ago CM_Tools.php 9 months ago LICENSE.txt 9 months ago changelog.md 9 months ago code-manager-config.php 9 months ago code-manager.php 9 months ago readme.txt 9 months ago
code-manager.php
242 lines
1 <?php
2
3 /**
4 * Plugin Name: Code Manager
5 * Plugin URI: https://code-manager.com/
6 * Description: Create, edit and organize PHP, JavaScript, CSS and HTML code from your WordPress dashboard.
7 * Version: 1.0.44
8 * Author: Passionate Programmers B.V.
9 * Author URI: https://code-manager.com/
10 * Text Domain: code-manager
11 * License:
12 * License URI:
13 * Domain Path: /languages
14 *
15 *
16 * @package .
17 * @author Peter Schulz
18 * @since 1.0.0
19 */
20 if ( !defined( 'WPINC' ) ) {
21 die;
22 }
23 if ( !defined( 'ABSPATH' ) ) {
24 exit;
25 }
26 if ( function_exists( 'code_manager_fs' ) ) {
27 code_manager_fs()->set_basename( false, __FILE__ );
28 } else {
29 // Load namespaces.
30 require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
31 // Set plugin version.
32 // Needs to be defined before activation, deactivation and uninstall hooks.
33 if ( !defined( 'CODE_MANAGER_VERSION' ) ) {
34 define( 'CODE_MANAGER_VERSION', '1.0.44' );
35 }
36 /**
37 * Create a helper function for easy SDK access.
38 *
39 * @return Freemius
40 * @throws Freemius_Exception
41 */
42 function code_manager_fs() {
43 global $code_manager_fs;
44 if ( !isset( $code_manager_fs ) ) {
45 // Include Freemius SDK.
46 require_once dirname( __FILE__ ) . '/vendor/freemius/start.php';
47 $code_manager_fs = fs_dynamic_init( array(
48 'id' => '6331',
49 'slug' => 'code-manager',
50 'type' => 'plugin',
51 'public_key' => 'pk_7a949f640a340d0addeee391d19d6',
52 'is_premium' => false,
53 'premium_suffix' => 'Premium',
54 'has_addons' => false,
55 'has_paid_plans' => true,
56 'trial' => array(
57 'days' => 14,
58 'is_require_payment' => false,
59 ),
60 'menu' => array(
61 'slug' => 'code_manager',
62 'contact' => false,
63 ),
64 'is_live' => true,
65 ) );
66 }
67 return $code_manager_fs;
68 }
69
70 // Init Freemius.
71 code_manager_fs();
72 // Signal that SDK was initiated.
73 do_action( 'code_manager_fs_loaded' );
74 /**
75 * Activate plugin
76 *
77 * @author Peter Schulz
78 * @since 1.0.0
79 */
80 function activate_code_manager() {
81 require_once plugin_dir_path( __FILE__ ) . 'includes/class-code-manager-switch.php';
82 Code_Manager_Switch::activate();
83 register_uninstall_hook( __FILE__, 'code_manager_uninstall' );
84 }
85
86 register_activation_hook( __FILE__, 'activate_code_manager' );
87 /**
88 * Deactivate plugin
89 *
90 * @author Peter Schulz
91 * @since 1.0.0
92 */
93 function deactivate_code_manager() {
94 require_once plugin_dir_path( __FILE__ ) . 'includes/class-code-manager-switch.php';
95 Code_Manager_Switch::deactivate();
96 }
97
98 register_deactivation_hook( __FILE__, 'deactivate_code_manager' );
99 /**
100 * Uninstall blog
101 *
102 * This functions is called when the plugin is uninstalled. The following actions are performed:
103 * + Drop plugin tables (unless settings indicate not to)
104 * + Delete plugin options from $wpdb->options (unless settings indicate not to)
105 *
106 * Actions are processed on the current blog and are repeated for every blog on a multisite installation. Must be
107 * called from the dashboard (WP_UNINSTALL_PLUGIN defined). User must have the proper privileges (activate_plugins).
108 *
109 * @author Peter Schulz
110 * @since 1.0.0
111 */
112 function code_manager_uninstall_blog() {
113 global $wpdb;
114 $wpdb->suppress_errors( true );
115 $drop_tables = get_option( 'code_manager_uninstall_tables' );
116 if ( !$drop_tables || 'on' === $drop_tables ) {
117 $drop_table = 'drop table if exists {wp_prefix}code_manager;';
118 $wpdb->query( str_replace( '{wp_prefix}', $wpdb->prefix, $drop_table ) );
119 }
120 $delete_options = get_option( 'code_manager_uninstall_options' );
121 if ( !$delete_options || 'on' === $delete_options ) {
122 // Delete Code Manager options.
123 $wpdb->query( "delete from {$wpdb->options} where option_name like 'code_manager_%'" );
124 // db call ok; no-cache ok.
125 }
126 }
127
128 /**
129 * Uninstall plugin
130 *
131 * @author Peter Schulz
132 * @since 1.0.0
133 */
134 function code_manager_uninstall() {
135 if ( is_multisite() ) {
136 global $wpdb;
137 // Uninstall plugin for all blogs one by one (will fail silently for blogs having no plugin tables/options).
138 $blogids = $wpdb->get_col( "select blog_id from {$wpdb->blogs}" );
139 // db call ok; no-cache ok.
140 foreach ( $blogids as $blog_id ) {
141 // Uninstall blog.
142 switch_to_blog( $blog_id );
143 code_manager_uninstall_blog();
144 restore_current_blog();
145 }
146 } else {
147 // Uninstall single site installation.
148 code_manager_uninstall_blog();
149 }
150 code_manager_fs()->add_action( 'after_uninstall', 'code_manager_fs_uninstall_cleanup' );
151 }
152
153 /**
154 * Remove preview code ids on login
155 *
156 * @param string $user_login User login.
157 * @since 1.0.0
158 */
159 function wpda_remove_user_preview_codes_on_login( $user_login ) {
160 $user = get_user_by( 'login', $user_login );
161 $user_id = $user->ID;
162 delete_user_meta( $user_id, 'code_manager_preview_code_ids' );
163 }
164
165 add_action( 'wp_login', 'wpda_remove_user_preview_codes_on_login', 99 );
166 /**
167 * Remove preview code ids on logout
168 *
169 * @param string $user_id User ID.
170 * @since 1.0.0
171 */
172 function wpda_remove_user_preview_codes_on_logout( $user_id ) {
173 delete_user_meta( $user_id, 'code_manager_preview_code_ids' );
174 }
175
176 add_action( 'wp_logout', 'wpda_remove_user_preview_codes_on_logout', 10 );
177 /**
178 * Send user to support page
179 *
180 * @param string $wp_org_support_forum_url Forum URL.
181 * @return string
182 * @throws Freemius_Exception
183 */
184 function cm_support_forum_url( $wp_org_support_forum_url ) {
185 if ( code_manager_fs()->is_premium() ) {
186 // Use different support page for premium version.
187 return 'https://users.freemius.com/store/2612';
188 }
189 return 'https://wordpress.org/support/plugin/code-manager/';
190 }
191
192 code_manager_fs()->add_filter( 'support_forum_url', 'cm_support_forum_url' );
193 /**
194 * Add Code Manager icon to freemius.
195 *
196 * @return string
197 */
198 function cm_freemius_icon() {
199 return dirname( __FILE__ ) . '/vendor/freemius/assets/img/code-manager.png';
200 }
201
202 code_manager_fs()->add_filter( 'plugin_icon', 'cm_freemius_icon' );
203 /**
204 * Handle freemius menu items.
205 *
206 * @param boolean $is_visible Visibility.
207 * @param string $submenu_id Sub menu id.
208 * @return bool|mixed
209 * @throws Freemius_Exception
210 */
211 function cm_freemius_menu_visible( $is_visible, $submenu_id ) {
212 // support, account, contact, pricing.
213 if ( 'contact' === $submenu_id ) {
214 $is_visible = false;
215 }
216 if ( code_manager_fs()->is_premium() && 'contact' === $submenu_id ) {
217 $is_visible = true;
218 }
219 return $is_visible;
220 }
221
222 code_manager_fs()->add_filter(
223 'is_submenu_visible',
224 'cm_freemius_menu_visible',
225 10,
226 2
227 );
228 /**
229 * Start plugin after loading all other installed and activated plugins to get access to their libraries
230 *
231 * @author Peter Schulz
232 * @since 1.0.0
233 */
234 function run_code_manager() {
235 require_once plugin_dir_path( __FILE__ ) . 'code-manager-config.php';
236 require_once plugin_dir_path( __FILE__ ) . 'includes/class-code-manager.php';
237 $code_manager = new Code_Manager();
238 $code_manager->run();
239 }
240
241 add_action( 'plugins_loaded', 'run_code_manager' );
242 }