DragDropBuilder
5 years ago
EmailSettings
5 years ago
ShortcodeBuilder
5 years ago
AbstractSettingsPage.php
5 years ago
AddNewForm.php
5 years ago
AdminFooter.php
5 years ago
ExtensionsSettingsPage.php
5 years ago
FormList.php
5 years ago
Forms.php
5 years ago
GeneralSettings.php
5 years ago
IDUserColumn.php
5 years ago
MemberDirectories.php
5 years ago
MembersDirectoryList.php
5 years ago
ToolsSettingsPage.php
5 years ago
index.php
5 years ago
ExtensionsSettingsPage.php
178 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Admin\SettingsPages; |
| 4 | |
| 5 | use ProfilePress\Core\Classes\ExtensionManager; |
| 6 | use ProfilePress\Core\Classes\ExtensionManager as EM; |
| 7 | use ProfilePress\Custom_Settings_Page_Api; |
| 8 | |
| 9 | class ExtensionsSettingsPage extends AbstractSettingsPage |
| 10 | { |
| 11 | public function __construct() |
| 12 | { |
| 13 | add_filter('ppress_admin_hooks', function () { |
| 14 | add_action('admin_menu', array($this, 'register_settings_page')); |
| 15 | }); |
| 16 | |
| 17 | if ( ! ExtensionManager::is_premium()) { |
| 18 | add_filter('install_plugins_tabs', [$this, 'add_extension_tab']); |
| 19 | add_action('install_plugins_ppress_extensions', [$this, 'extension_view']); |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | public function add_extension_tab($tabs) |
| 24 | { |
| 25 | $tabs['ppress_extensions'] = 'ProfilePress ' . __('Addons', 'wp-user-avatar'); |
| 26 | |
| 27 | return $tabs; |
| 28 | } |
| 29 | |
| 30 | public function extension_view($tabs) |
| 31 | { |
| 32 | $this->admin_page_callback(); |
| 33 | } |
| 34 | |
| 35 | public function admin_page_title() |
| 36 | { |
| 37 | return esc_html__('Addons', 'wp-user-avatar'); |
| 38 | } |
| 39 | |
| 40 | public function register_settings_page() |
| 41 | { |
| 42 | add_submenu_page( |
| 43 | PPRESS_SETTINGS_SLUG, |
| 44 | $this->admin_page_title() . ' - ProfilePress', |
| 45 | '<span style="color:#f18500">' . $this->admin_page_title() . '</span>', |
| 46 | 'manage_options', |
| 47 | PPRESS_EXTENSIONS_SETTINGS_SLUG, |
| 48 | [$this, 'settings_page_function']); |
| 49 | } |
| 50 | |
| 51 | public function settings_page_function() |
| 52 | { |
| 53 | add_action('wp_cspa_main_content_area', array($this, 'admin_page_callback'), 10, 2); |
| 54 | add_action('wp_cspa_form_tag', function () { |
| 55 | echo 'id="ppress-extension-manager-form"'; |
| 56 | }); |
| 57 | |
| 58 | $instance = Custom_Settings_Page_Api::instance(); |
| 59 | $instance->option_name(EM::DB_OPTION_NAME); |
| 60 | $instance->add_view_classes('ppress-extensions'); |
| 61 | $instance->page_header($this->admin_page_title()); |
| 62 | $this->register_core_settings($instance, true); |
| 63 | $instance->build(true); |
| 64 | } |
| 65 | |
| 66 | public function admin_page_callback() |
| 67 | { |
| 68 | ?> |
| 69 | <div class="ppress-extensions-items-wrap"> |
| 70 | <?php if (EM::is_premium()) : ?> |
| 71 | <div class="ppress-extensions-header"> |
| 72 | <div class="ppress-extensions-header-buttons"> |
| 73 | <div class="button-content"> |
| 74 | <button type="button" class="button-primary ppress-extensions-button" onclick="jQuery('.ppress-extension-manager-checkbox').prop('checked', true);jQuery('#ppress-extension-manager-form').submit();"> |
| 75 | <?= esc_html__('Activate All', 'wp-user-avatar') ?> |
| 76 | </button> |
| 77 | <button type="button" class="button-secondary ppress-extensions-button" onclick="jQuery('.ppress-extension-manager-checkbox').prop('checked', false);jQuery('#ppress-extension-manager-form').submit();"> |
| 78 | <?= esc_html__('Deactivate All', 'wp-user-avatar') ?> |
| 79 | </button> |
| 80 | </div> |
| 81 | </div> |
| 82 | </div> |
| 83 | <?php else : ?> |
| 84 | <div class="ppress-extensions-upsell-wrap"> |
| 85 | <div class="notice-content"> |
| 86 | <span> |
| 87 | <?= sprintf( |
| 88 | esc_html__('Upgrade to Premium to unlock extensions and other great features. As a valued ProfilePress Lite user, you will %1$sreceive 20%3$s off%2$s your purchase, automatically applied at checkout!', 'wp-user-avatar'), |
| 89 | '<span class="ppress-extensions-upsell-highlight">', '</span>', '%' |
| 90 | ) ?> |
| 91 | </span> |
| 92 | <div class="ppress-extensions-upsell-button"> |
| 93 | <a target="_blank" href="https://profilepress.net/pricing/?discount=20PPOFF&utm_source=liteplugin&utm_medium=extension-page&utm_campaign=notice&utm_content=upsell" class="button-primary"> |
| 94 | <?= esc_html__('Upgrade Now', 'wp-user-avatar') ?> |
| 95 | </a> |
| 96 | </div> |
| 97 | </div> |
| 98 | </div> |
| 99 | <?php endif; ?> |
| 100 | <div class="ppress-extensions-items-row"> |
| 101 | |
| 102 | <?php foreach (EM::available_extensions() as $id => $extension) : |
| 103 | $name = sprintf('%s[%s]', EM::DB_OPTION_NAME, $id); |
| 104 | $extension_class = ppress_var(EM::class_map(), $id); |
| 105 | $upgrade_url = "https://profilepress.net/pricing/?utm_source=WordPress&utm_campaign=liteplugin&utm_medium=extension-upgrade&utm_content=$id"; |
| 106 | if ( ! EM::is_premium()) { |
| 107 | $upgrade_url = add_query_arg('discount', '20PPOFF', $upgrade_url); |
| 108 | } |
| 109 | |
| 110 | $upgrade_label = ! EM::is_premium() ? esc_html__('Upgrade to Premium', 'wp-user-avatar') : esc_html__('Upgrade Plan', 'wp-user-avatar'); |
| 111 | |
| 112 | ?> |
| 113 | |
| 114 | <?php $dependency_available = isset($extension['is_available']) && true !== ($callable_result = call_user_func($extension['is_available'])) ? $callable_result : true; ?> |
| 115 | <div class="ppress-extension-item-wrap"> |
| 116 | <div class="ppress-extension-item-card"> |
| 117 | <div class="ppress-extension-card-body<?= EM::is_premium() && $extension_class::$instance_flag && (true !== $dependency_available) ? ' ppress-unavailable' : '' ?>"> |
| 118 | <div class="ppress-extension-card-header"> |
| 119 | <?= ppress_var($extension, 'icon', '') ?> |
| 120 | <?= $extension['title'] ?> |
| 121 | </div> |
| 122 | <div class="ppress-extension-card-description"> |
| 123 | <div><?= $extension['description'] ?></div> |
| 124 | <div class="ppress-extension-card-learn-more"> |
| 125 | <a href="<?= $extension['url'] ?>" target="_blank"><?= esc_html__('Learn More', 'wp-user-avatar') ?></a> |
| 126 | <a href="<?= $extension['url'] ?>" target="_blank" class="no-underline"> →</a> |
| 127 | </div> |
| 128 | </div> |
| 129 | </div> |
| 130 | <div class="ppress-extension-card-footer"> |
| 131 | |
| 132 | <?php if (EM::is_premium() && $extension_class::$instance_flag) : ?> |
| 133 | |
| 134 | <?php if (true !== $dependency_available) : ?> |
| 135 | <span class="ppress-extension-status"> |
| 136 | <?= sprintf(esc_html__('Unavailable: %s', 'wp-user-avatar'), "<span>$callable_result</span>") ?> |
| 137 | </span> |
| 138 | <?php else : ?> |
| 139 | <div class="ppress-extension-card-install-activate"> |
| 140 | <span class="ppress-extension-card-status"> |
| 141 | <?= EM::is_enabled($id) ? esc_html__('Activated', 'wp-user-avatar') : esc_html__('Deactivated', 'wp-user-avatar') ?> |
| 142 | </span> |
| 143 | <label for="ppress-<?= $id ?>"> |
| 144 | <input type="hidden" name="<?= $name ?>" value="false"> |
| 145 | <input class="ppress-extension-manager-checkbox" type="checkbox" name="<?= $name ?>" id="ppress-<?= $id ?>" value="true" onchange="jQuery('#ppress-extension-manager-form').submit();" <?php checked(EM::is_enabled($id)) ?>> |
| 146 | <span class="ppress-extension-use-switch"></span> |
| 147 | </label> |
| 148 | </div> |
| 149 | <?php endif; ?> |
| 150 | |
| 151 | <?php else : ?> |
| 152 | <div class="ppress-extensions-upgrade-cta"> |
| 153 | <a class="button-primary ppress-extensions-button" href="<?= $upgrade_url ?>" target="_blank"> |
| 154 | <?= $upgrade_label ?> |
| 155 | </a> |
| 156 | </div> |
| 157 | <?php endif; ?> |
| 158 | </div> |
| 159 | </div> |
| 160 | </div> |
| 161 | <?php endforeach; ?> |
| 162 | </div> |
| 163 | <input type="hidden" name="save_ppress_extension_manager" value="true"> |
| 164 | </div> |
| 165 | <?php |
| 166 | } |
| 167 | |
| 168 | public static function get_instance() |
| 169 | { |
| 170 | static $instance = null; |
| 171 | |
| 172 | if (is_null($instance)) { |
| 173 | $instance = new self(); |
| 174 | } |
| 175 | |
| 176 | return $instance; |
| 177 | } |
| 178 | } |