code-manager
Last commit date
Code_Manager
2 months ago
admin
2 months ago
assets
2 months ago
includes
2 months ago
public
2 months ago
vendor
2 months ago
CM_Tools.php
2 months ago
LICENSE.txt
2 months ago
changelog.md
2 months ago
code-manager-config.php
2 months ago
code-manager.php
2 months ago
readme.txt
1 month ago
code-manager.php
243 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.46 |
| 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.46' ); |
| 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 | 'is_org_compliant' => true, |
| 66 | ) ); |
| 67 | } |
| 68 | return $code_manager_fs; |
| 69 | } |
| 70 | |
| 71 | // Init Freemius. |
| 72 | code_manager_fs(); |
| 73 | // Signal that SDK was initiated. |
| 74 | do_action( 'code_manager_fs_loaded' ); |
| 75 | /** |
| 76 | * Activate plugin |
| 77 | * |
| 78 | * @author Peter Schulz |
| 79 | * @since 1.0.0 |
| 80 | */ |
| 81 | function activate_code_manager() { |
| 82 | require_once plugin_dir_path( __FILE__ ) . 'includes/class-code-manager-switch.php'; |
| 83 | Code_Manager_Switch::activate(); |
| 84 | register_uninstall_hook( __FILE__, 'code_manager_uninstall' ); |
| 85 | } |
| 86 | |
| 87 | register_activation_hook( __FILE__, 'activate_code_manager' ); |
| 88 | /** |
| 89 | * Deactivate plugin |
| 90 | * |
| 91 | * @author Peter Schulz |
| 92 | * @since 1.0.0 |
| 93 | */ |
| 94 | function deactivate_code_manager() { |
| 95 | require_once plugin_dir_path( __FILE__ ) . 'includes/class-code-manager-switch.php'; |
| 96 | Code_Manager_Switch::deactivate(); |
| 97 | } |
| 98 | |
| 99 | register_deactivation_hook( __FILE__, 'deactivate_code_manager' ); |
| 100 | /** |
| 101 | * Uninstall blog |
| 102 | * |
| 103 | * This functions is called when the plugin is uninstalled. The following actions are performed: |
| 104 | * + Drop plugin tables (unless settings indicate not to) |
| 105 | * + Delete plugin options from $wpdb->options (unless settings indicate not to) |
| 106 | * |
| 107 | * Actions are processed on the current blog and are repeated for every blog on a multisite installation. Must be |
| 108 | * called from the dashboard (WP_UNINSTALL_PLUGIN defined). User must have the proper privileges (activate_plugins). |
| 109 | * |
| 110 | * @author Peter Schulz |
| 111 | * @since 1.0.0 |
| 112 | */ |
| 113 | function code_manager_uninstall_blog() { |
| 114 | global $wpdb; |
| 115 | $wpdb->suppress_errors( true ); |
| 116 | $drop_tables = get_option( 'code_manager_uninstall_tables' ); |
| 117 | if ( !$drop_tables || 'on' === $drop_tables ) { |
| 118 | $drop_table = 'drop table if exists {wp_prefix}code_manager;'; |
| 119 | $wpdb->query( str_replace( '{wp_prefix}', $wpdb->prefix, $drop_table ) ); |
| 120 | } |
| 121 | $delete_options = get_option( 'code_manager_uninstall_options' ); |
| 122 | if ( !$delete_options || 'on' === $delete_options ) { |
| 123 | // Delete Code Manager options. |
| 124 | $wpdb->query( "delete from {$wpdb->options} where option_name like 'code_manager_%'" ); |
| 125 | // db call ok; no-cache ok. |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Uninstall plugin |
| 131 | * |
| 132 | * @author Peter Schulz |
| 133 | * @since 1.0.0 |
| 134 | */ |
| 135 | function code_manager_uninstall() { |
| 136 | if ( is_multisite() ) { |
| 137 | global $wpdb; |
| 138 | // Uninstall plugin for all blogs one by one (will fail silently for blogs having no plugin tables/options). |
| 139 | $blogids = $wpdb->get_col( "select blog_id from {$wpdb->blogs}" ); |
| 140 | // db call ok; no-cache ok. |
| 141 | foreach ( $blogids as $blog_id ) { |
| 142 | // Uninstall blog. |
| 143 | switch_to_blog( $blog_id ); |
| 144 | code_manager_uninstall_blog(); |
| 145 | restore_current_blog(); |
| 146 | } |
| 147 | } else { |
| 148 | // Uninstall single site installation. |
| 149 | code_manager_uninstall_blog(); |
| 150 | } |
| 151 | code_manager_fs()->add_action( 'after_uninstall', 'code_manager_fs_uninstall_cleanup' ); |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * Remove preview code ids on login |
| 156 | * |
| 157 | * @param string $user_login User login. |
| 158 | * @since 1.0.0 |
| 159 | */ |
| 160 | function wpda_remove_user_preview_codes_on_login( $user_login ) { |
| 161 | $user = get_user_by( 'login', $user_login ); |
| 162 | $user_id = $user->ID; |
| 163 | delete_user_meta( $user_id, 'code_manager_preview_code_ids' ); |
| 164 | } |
| 165 | |
| 166 | add_action( 'wp_login', 'wpda_remove_user_preview_codes_on_login', 99 ); |
| 167 | /** |
| 168 | * Remove preview code ids on logout |
| 169 | * |
| 170 | * @param string $user_id User ID. |
| 171 | * @since 1.0.0 |
| 172 | */ |
| 173 | function wpda_remove_user_preview_codes_on_logout( $user_id ) { |
| 174 | delete_user_meta( $user_id, 'code_manager_preview_code_ids' ); |
| 175 | } |
| 176 | |
| 177 | add_action( 'wp_logout', 'wpda_remove_user_preview_codes_on_logout', 10 ); |
| 178 | /** |
| 179 | * Send user to support page |
| 180 | * |
| 181 | * @param string $wp_org_support_forum_url Forum URL. |
| 182 | * @return string |
| 183 | * @throws Freemius_Exception |
| 184 | */ |
| 185 | function cm_support_forum_url( $wp_org_support_forum_url ) { |
| 186 | if ( code_manager_fs()->is_premium() ) { |
| 187 | // Use different support page for premium version. |
| 188 | return 'https://users.freemius.com/store/2612'; |
| 189 | } |
| 190 | return 'https://wordpress.org/support/plugin/code-manager/'; |
| 191 | } |
| 192 | |
| 193 | code_manager_fs()->add_filter( 'support_forum_url', 'cm_support_forum_url' ); |
| 194 | /** |
| 195 | * Add Code Manager icon to freemius. |
| 196 | * |
| 197 | * @return string |
| 198 | */ |
| 199 | function cm_freemius_icon() { |
| 200 | return dirname( __FILE__ ) . '/vendor/freemius/assets/img/code-manager.png'; |
| 201 | } |
| 202 | |
| 203 | code_manager_fs()->add_filter( 'plugin_icon', 'cm_freemius_icon' ); |
| 204 | /** |
| 205 | * Handle freemius menu items. |
| 206 | * |
| 207 | * @param boolean $is_visible Visibility. |
| 208 | * @param string $submenu_id Sub menu id. |
| 209 | * @return bool|mixed |
| 210 | * @throws Freemius_Exception |
| 211 | */ |
| 212 | function cm_freemius_menu_visible( $is_visible, $submenu_id ) { |
| 213 | // support, account, contact, pricing. |
| 214 | if ( 'contact' === $submenu_id ) { |
| 215 | $is_visible = false; |
| 216 | } |
| 217 | if ( code_manager_fs()->is_premium() && 'contact' === $submenu_id ) { |
| 218 | $is_visible = true; |
| 219 | } |
| 220 | return $is_visible; |
| 221 | } |
| 222 | |
| 223 | code_manager_fs()->add_filter( |
| 224 | 'is_submenu_visible', |
| 225 | 'cm_freemius_menu_visible', |
| 226 | 10, |
| 227 | 2 |
| 228 | ); |
| 229 | /** |
| 230 | * Start plugin after loading all other installed and activated plugins to get access to their libraries |
| 231 | * |
| 232 | * @author Peter Schulz |
| 233 | * @since 1.0.0 |
| 234 | */ |
| 235 | function run_code_manager() { |
| 236 | require_once plugin_dir_path( __FILE__ ) . 'code-manager-config.php'; |
| 237 | require_once plugin_dir_path( __FILE__ ) . 'includes/class-code-manager.php'; |
| 238 | $code_manager = new Code_Manager(); |
| 239 | $code_manager->run(); |
| 240 | } |
| 241 | |
| 242 | add_action( 'plugins_loaded', 'run_code_manager' ); |
| 243 | } |