PluginProbe ʕ •ᴥ•ʔ
Code Manager / 1.0.15
Code Manager v1.0.15
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 4 years ago admin 4 years ago assets 4 years ago freemius 4 years ago includes 4 years ago public 4 years ago vendor 4 years ago .gitignore 4 years ago CHANGES.md 4 years ago LICENSE.txt 4 years ago README.md 4 years ago code-manager-config.php 4 years ago code-manager.php 4 years ago composer.json 4 years ago readme.txt 4 years ago todo.txt 4 years ago
code-manager.php
263 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.15
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
27 if ( function_exists( 'code_manager_fs' ) ) {
28 code_manager_fs()->set_basename( false, __FILE__ );
29 } else {
30 // Load namespaces.
31 require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
32 // Set plugin version.
33 // Needs to be defined before activation, deactivation and uninstall hooks.
34 if ( !defined( 'CODE_MANAGER_VERSION' ) ) {
35 define( 'CODE_MANAGER_VERSION', '1.0.15' );
36 }
37 /**
38 * Create a helper function for easy SDK access.
39 *
40 * @return Freemius
41 * @throws Freemius_Exception
42 */
43 function code_manager_fs()
44 {
45 global $code_manager_fs ;
46
47 if ( !isset( $code_manager_fs ) ) {
48 // Include Freemius SDK.
49 require_once dirname( __FILE__ ) . '/freemius/start.php';
50 $code_manager_fs = fs_dynamic_init( array(
51 'id' => '6331',
52 'slug' => 'code-manager',
53 'type' => 'plugin',
54 'public_key' => 'pk_7a949f640a340d0addeee391d19d6',
55 'is_premium' => false,
56 'premium_suffix' => 'Premium',
57 'has_addons' => false,
58 'has_paid_plans' => true,
59 'trial' => array(
60 'days' => 14,
61 'is_require_payment' => false,
62 ),
63 'menu' => array(
64 'slug' => 'code_manager',
65 'contact' => false,
66 ),
67 'is_live' => true,
68 ) );
69 }
70
71 return $code_manager_fs;
72 }
73
74 // Init Freemius.
75 code_manager_fs();
76 // Signal that SDK was initiated.
77 do_action( 'code_manager_fs_loaded' );
78 /**
79 * Activate plugin
80 *
81 * @author Peter Schulz
82 * @since 1.0.0
83 */
84 function activate_code_manager()
85 {
86 require_once plugin_dir_path( __FILE__ ) . 'includes/class-code-manager-switch.php';
87 Code_Manager_Switch::activate();
88 register_uninstall_hook( __FILE__, 'code_manager_uninstall' );
89 }
90
91 register_activation_hook( __FILE__, 'activate_code_manager' );
92 /**
93 * Deactivate plugin
94 *
95 * @author Peter Schulz
96 * @since 1.0.0
97 */
98 function deactivate_code_manager()
99 {
100 require_once plugin_dir_path( __FILE__ ) . 'includes/class-code-manager-switch.php';
101 Code_Manager_Switch::deactivate();
102 }
103
104 register_deactivation_hook( __FILE__, 'deactivate_code_manager' );
105 /**
106 * Uninstall blog
107 *
108 * This functions is called when the plugin is uninstalled. The following actions are performed:
109 * + Drop plugin tables (unless settings indicate not to)
110 * + Delete plugin options from $wpdb->options (unless settings indicate not to)
111 *
112 * Actions are processed on the current blog and are repeated for every blog on a multisite installation. Must be
113 * called from the dashboard (WP_UNINSTALL_PLUGIN defined). User must have the proper privileges (activate_plugins).
114 *
115 * @author Peter Schulz
116 * @since 1.0.0
117 */
118 function code_manager_uninstall_blog()
119 {
120 global $wpdb ;
121 $wpdb->suppress_errors( true );
122 $drop_tables = get_option( 'code_manager_uninstall_tables' );
123
124 if ( !$drop_tables || 'on' === $drop_tables ) {
125 $drop_table = 'drop table if exists {wp_prefix}code_manager;';
126 $wpdb->query( str_replace( '{wp_prefix}', $wpdb->prefix, $drop_table ) );
127 }
128
129 $delete_options = get_option( 'code_manager_uninstall_options' );
130
131 if ( !$delete_options || 'on' === $delete_options ) {
132 // Delete Code Manager options.
133 $wpdb->query( "delete from {$wpdb->options} where option_name like 'code_manager_%'" );
134 // db call ok; no-cache ok.
135 }
136
137 }
138
139 /**
140 * Uninstall plugin
141 *
142 * @author Peter Schulz
143 * @since 1.0.0
144 */
145 function code_manager_uninstall()
146 {
147
148 if ( is_multisite() ) {
149 global $wpdb ;
150 // Uninstall plugin for all blogs one by one (will fail silently for blogs having no plugin tables/options).
151 $blogids = $wpdb->get_col( "select blog_id from {$wpdb->blogs}" );
152 // db call ok; no-cache ok.
153 foreach ( $blogids as $blog_id ) {
154 // Uninstall blog.
155 switch_to_blog( $blog_id );
156 code_manager_uninstall_blog();
157 restore_current_blog();
158 }
159 } else {
160 // Uninstall single site installation.
161 code_manager_uninstall_blog();
162 }
163
164 code_manager_fs()->add_action( 'after_uninstall', 'code_manager_fs_uninstall_cleanup' );
165 }
166
167 /**
168 * Remove preview code ids on login
169 *
170 * @param string $user_login User login.
171 * @since 1.0.0
172 */
173 function wpda_remove_user_preview_codes_on_login( $user_login )
174 {
175 $user = get_user_by( 'login', $user_login );
176 $user_id = $user->ID;
177 delete_user_meta( $user_id, 'code_manager_preview_code_ids' );
178 }
179
180 add_action( 'wp_login', 'wpda_remove_user_preview_codes_on_login', 99 );
181 /**
182 * Remove preview code ids on logout
183 *
184 * @param string $user_id User ID.
185 * @since 1.0.0
186 */
187 function wpda_remove_user_preview_codes_on_logout( $user_id )
188 {
189 delete_user_meta( $user_id, 'code_manager_preview_code_ids' );
190 }
191
192 add_action( 'wp_logout', 'wpda_remove_user_preview_codes_on_logout', 10 );
193 /**
194 * Send user to support page
195 *
196 * @param string $wp_org_support_forum_url Forum URL.
197 * @return string
198 * @throws Freemius_Exception
199 */
200 function cm_support_forum_url( $wp_org_support_forum_url )
201 {
202 if ( code_manager_fs()->is_premium() ) {
203 // Use different support page for premium version.
204 return 'https://users.freemius.com/store/2612';
205 }
206 return 'https://wordpress.org/support/plugin/code-manager/';
207 }
208
209 code_manager_fs()->add_filter( 'support_forum_url', 'cm_support_forum_url' );
210 /**
211 * Add Code Manager icon to freemius.
212 *
213 * @return string
214 */
215 function cm_freemius_icon()
216 {
217 return dirname( __FILE__ ) . '/freemius/assets/img/code-manager.png';
218 }
219
220 code_manager_fs()->add_filter( 'plugin_icon', 'cm_freemius_icon' );
221 /**
222 * Handle freemius menu items.
223 *
224 * @param boolean $is_visible Visibility.
225 * @param string $submenu_id Sub menu id.
226 * @return bool|mixed
227 * @throws Freemius_Exception
228 */
229 function cm_freemius_menu_visible( $is_visible, $submenu_id )
230 {
231 // support, account, contact, pricing.
232 if ( 'contact' === $submenu_id ) {
233 $is_visible = false;
234 }
235 if ( code_manager_fs()->is_premium() && 'contact' === $submenu_id ) {
236 $is_visible = true;
237 }
238 return $is_visible;
239 }
240
241 code_manager_fs()->add_filter(
242 'is_submenu_visible',
243 'cm_freemius_menu_visible',
244 10,
245 2
246 );
247 /**
248 * Start plugin after loading all other installed and activated plugins to get access to their libraries
249 *
250 * @author Peter Schulz
251 * @since 1.0.0
252 */
253 function run_code_manager()
254 {
255 require_once plugin_dir_path( __FILE__ ) . 'code-manager-config.php';
256 require_once plugin_dir_path( __FILE__ ) . 'includes/class-code-manager.php';
257 $code_manager = new Code_Manager();
258 $code_manager->run();
259 }
260
261 add_action( 'plugins_loaded', 'run_code_manager' );
262 }
263