admin
3 months ago
pagebuilders
3 months ago
snippets
3 months ago
widgets
3 months ago
ajax-functions.php
3 months ago
extras.php
3 months ago
install.php
3 months ago
scripts.php
3 months ago
transient.php
3 months ago
install.php
124 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Install Function |
| 5 | * |
| 6 | * @copyright Copyright (c) 2016, Jeffrey Carandang |
| 7 | * @since 3.0 |
| 8 | */ |
| 9 | // Exit if accessed directly |
| 10 | if (!defined('ABSPATH')) exit; |
| 11 | |
| 12 | //check if free version is activated |
| 13 | if (!function_exists('widgetopts_upgraded')) { |
| 14 | add_action('admin_notices', 'widgetopts_upgraded'); |
| 15 | function widgetopts_upgraded() |
| 16 | { |
| 17 | if (is_plugin_active('widget-options/plugin.php') && is_plugin_active('extended-widget-options/plugin.php')) { ?> |
| 18 | <div class="widgetopts_activated_notice notice-error notice" style="box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);"> |
| 19 | <p> |
| 20 | <?php _e('Please deactivate <strong>Widget Options</strong> Plugin, it may cause issue with the extended plugin version. Thanks!', 'widget-options'); ?> |
| 21 | </p> |
| 22 | </div> |
| 23 | <?php } |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | //add settings link on plugin page |
| 28 | if (!function_exists('widgetopts_filter_plugin_actions')) { |
| 29 | add_action('plugin_action_links_' . plugin_basename(WIDGETOPTS_PLUGIN_FILE), 'widgetopts_filter_plugin_actions'); |
| 30 | function widgetopts_filter_plugin_actions($links) |
| 31 | { |
| 32 | |
| 33 | if (!is_array($links)) { |
| 34 | $links = array(); |
| 35 | } |
| 36 | |
| 37 | $links[] = '<a href="' . esc_url(admin_url('options-general.php?page=widgetopts_plugin_settings')) . '">' . __('Settings', 'widget-options') . '</a>'; |
| 38 | $upgrade_link = apply_filters('widget_options_site_url', trailingslashit(WIDGETOPTS_PLUGIN_WEBSITE) . 'pricing/?utm_source=upgradebtn&utm_medium=plugins&utm_campaign=widgetoptspluginlink'); |
| 39 | $links[] = '<a href="' . esc_url($upgrade_link) . '" target="_blank" style="color: #3db634">' . __('Upgrade', 'widget-options') . '</a>'; |
| 40 | return $links; |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | //register default values |
| 45 | if (!function_exists('widgetopts_register_defaults')) { |
| 46 | register_activation_hook(WIDGETOPTS_PLUGIN_FILE, function () { |
| 47 | add_option('Activated_Plugin', WIDGETOPTS_PLUGIN_FILE); |
| 48 | update_option('widgetopts_force_migration_rescan', 1); |
| 49 | update_option('widgetopts_legacy_migration_notice_token', (string) time()); |
| 50 | widgetopts_register_defaults(); |
| 51 | }); |
| 52 | |
| 53 | add_action('admin_init', function () { |
| 54 | if (is_admin() && get_option('widgetopts_force_migration_rescan')) { |
| 55 | delete_option('widgetopts_force_migration_rescan'); |
| 56 | if (class_exists('WidgetOpts_Snippets_Migration')) { |
| 57 | WidgetOpts_Snippets_Migration::rescan_and_update_flag(); |
| 58 | } elseif (class_exists('WidgetOpts_Snippets_CPT')) { |
| 59 | delete_option('wopts_display_logic_migration_required'); |
| 60 | WidgetOpts_Snippets_CPT::scan_for_legacy_logic(); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if (is_admin() && get_option('Activated_Plugin') == WIDGETOPTS_PLUGIN_FILE) { |
| 65 | delete_option('Activated_Plugin'); |
| 66 | exit(wp_redirect(admin_url('options-general.php?page=widgetopts_plugin_settings'))); |
| 67 | } |
| 68 | }); |
| 69 | |
| 70 | add_action('plugins_loaded', 'widgetopts_register_defaults'); |
| 71 | function widgetopts_register_defaults() |
| 72 | { |
| 73 | if (is_admin()) { |
| 74 | |
| 75 | if (!get_option('widgetopts_installDate')) { |
| 76 | add_option('widgetopts_installDate', date('Y-m-d h:i:s')); |
| 77 | } |
| 78 | |
| 79 | if (!get_option('_widgetopts_default_registered_')) { |
| 80 | //activate free version modules |
| 81 | add_option('widgetopts_tabmodule-visibility', 'activate'); |
| 82 | add_option('widgetopts_tabmodule-devices', 'activate'); |
| 83 | add_option('widgetopts_tabmodule-alignment', 'activate'); |
| 84 | add_option('widgetopts_tabmodule-hide_title', 'activate'); |
| 85 | add_option('widgetopts_tabmodule-classes', 'activate'); |
| 86 | add_option('widgetopts_tabmodule-logic', 'activate'); |
| 87 | add_option('widgetopts_tabmodule-state', 'activate'); |
| 88 | add_option('widgetopts_tabmodule-classic_widgets_screen', 'activate'); |
| 89 | //add free version settings |
| 90 | $defaults = array( |
| 91 | 'visibility' => array( |
| 92 | 'post_type' => '1', |
| 93 | 'taxonomies' => '1', |
| 94 | 'misc' => '1' |
| 95 | ), |
| 96 | 'classes' => array( |
| 97 | 'id' => '1', |
| 98 | 'type' => 'both' |
| 99 | ), |
| 100 | ); |
| 101 | //upgraded settings from previous version |
| 102 | $options = get_option('extwopts_class_settings'); |
| 103 | if (isset($options['class_field'])) { |
| 104 | $defaults['classes']['type'] = $options['class_field']; |
| 105 | } |
| 106 | if (isset($options['classlists'])) { |
| 107 | $defaults['classes']['classlists'] = $options['classlists']; |
| 108 | } |
| 109 | add_option('widgetopts_tabmodule-settings', serialize($defaults)); |
| 110 | add_option('_widgetopts_default_registered_', '1'); |
| 111 | delete_transient('widgetopts_tabs_transient'); //remove transient for settings |
| 112 | delete_option('widgetopts_settings'); |
| 113 | } |
| 114 | |
| 115 | //make sure to delete previous pages cache |
| 116 | if (!get_option('widgetopts_removed_global_pages')) { |
| 117 | delete_option('widgetopts_global_pages'); |
| 118 | add_option('widgetopts_removed_global_pages', 1); |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | ?> |