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