DragDropBuilder
1 month ago
EmailSettings
1 year ago
Membership
1 month ago
AbstractSettingsPage.php
2 years ago
AddNewForm.php
1 year ago
AdminFooter.php
4 years ago
ExtensionsSettingsPage.php
1 year ago
FormList.php
4 months ago
Forms.php
1 year ago
FuseWP.php
3 years ago
GeneralSettings.php
9 months ago
IDUserColumn.php
5 years ago
LicenseUpgrader.php
3 years ago
MailOptin.php
3 years ago
MemberDirectories.php
1 year ago
MembersDirectoryList.php
4 years ago
ToolsSettingsPage.php
4 years ago
index.php
3 years ago
MemberDirectories.php
208 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Admin\SettingsPages; |
| 4 | |
| 5 | use ProfilePress\Core\Admin\SettingsPages\DragDropBuilder\DragDropBuilder; |
| 6 | use ProfilePress\Core\Classes\FormRepository as FR; |
| 7 | use ProfilePress\Custom_Settings_Page_Api; |
| 8 | |
| 9 | // Exit if accessed directly |
| 10 | if ( ! defined('ABSPATH')) { |
| 11 | exit; |
| 12 | } |
| 13 | |
| 14 | class MemberDirectories extends AbstractSettingsPage |
| 15 | { |
| 16 | /** |
| 17 | * @var FormList |
| 18 | */ |
| 19 | protected $wplist_instance; |
| 20 | protected $DragDropClassInstance; |
| 21 | |
| 22 | public function __construct() |
| 23 | { |
| 24 | add_action('ppress_register_menu_page', array($this, 'register_settings_page')); |
| 25 | add_action('ppress_admin_settings_page_member-directories', [$this, 'settings_admin_page_callback']); |
| 26 | add_action('ppress_admin_settings_page_add-new', [$this, 'settings_admin_page_callback']); |
| 27 | add_action('ppress_admin_settings_page_edit-shortcode-member-directory', [$this, 'settings_admin_page_callback']); |
| 28 | |
| 29 | add_filter('set-screen-option', array($this, 'set_screen'), 10, 3); |
| 30 | add_filter('set_screen_option_forms_per_page', array($this, 'set_screen'), 10, 3); |
| 31 | |
| 32 | $this->DragDropClassInstance = DragDropBuilder::get_instance(); |
| 33 | |
| 34 | do_action('ppress_admin_member_directory_class_constructor'); |
| 35 | } |
| 36 | |
| 37 | public function admin_page_title(): string |
| 38 | { |
| 39 | $page_title = esc_html__('Member Directories', 'wp-user-avatar'); |
| 40 | |
| 41 | if ( ! empty($_GET['page']) && $_GET['page'] == PPRESS_MEMBER_DIRECTORIES_SLUG) { |
| 42 | |
| 43 | if ( ! empty($_GET['view'])) { |
| 44 | if ($_GET['view'] === 'add') $page_title = esc_html__('Add Member Directory', 'wp-user-avatar'); |
| 45 | |
| 46 | if ($_GET['view'] === 'edit-shortcode-member-directory' || |
| 47 | ( ! empty($_GET['form-type']) && $_GET['form-type'] == FR::MEMBERS_DIRECTORY_TYPE)) { |
| 48 | $page_title = esc_html__('Edit Member Directory', 'wp-user-avatar'); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | return $page_title; |
| 54 | } |
| 55 | |
| 56 | public function register_settings_page() |
| 57 | { |
| 58 | $hook = add_submenu_page( |
| 59 | PPRESS_DASHBOARD_SETTINGS_SLUG, |
| 60 | 'ProfilePress ' . $this->admin_page_title(), |
| 61 | esc_html__('Member Directories', 'wp-user-avatar'), |
| 62 | 'manage_options', |
| 63 | PPRESS_MEMBER_DIRECTORIES_SLUG, |
| 64 | array($this, 'admin_page_callback') |
| 65 | ); |
| 66 | |
| 67 | add_action("load-$hook", array($this, 'screen_option')); |
| 68 | } |
| 69 | |
| 70 | public function default_header_menu() |
| 71 | { |
| 72 | return 'member-directories'; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Save screen option. |
| 77 | * |
| 78 | * @param string $status |
| 79 | * @param string $option |
| 80 | * @param string $value |
| 81 | * |
| 82 | * @return mixed |
| 83 | */ |
| 84 | public function set_screen($status, $option, $value) |
| 85 | { |
| 86 | return $value; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Screen options |
| 91 | */ |
| 92 | public function screen_option() |
| 93 | { |
| 94 | if (isset($_GET['page'], $_GET['view']) && strpos($_GET['view'], 'edit-shortcode') !== false) return; |
| 95 | |
| 96 | $args = [ |
| 97 | 'label' => esc_html__('Member Directories', 'wp-user-avatar'), |
| 98 | 'default' => 10, |
| 99 | 'option' => 'forms_per_page', |
| 100 | ]; |
| 101 | |
| 102 | add_screen_option('per_page', $args); |
| 103 | |
| 104 | if (isset($_GET['id']) || ppress_var($_GET, 'view') == 'add-new') { |
| 105 | add_filter('screen_options_show_screen', '__return_false'); |
| 106 | } |
| 107 | |
| 108 | $this->wplist_instance = MembersDirectoryList::get_instance(); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * @param $echo |
| 113 | * |
| 114 | * @return string|void |
| 115 | */ |
| 116 | public function live_form_preview_btn($echo = true) |
| 117 | { |
| 118 | if ( ! isset($_GET['view'])) return; |
| 119 | |
| 120 | $preview_url = esc_url(add_query_arg( |
| 121 | ['pp_preview_form' => absint($_GET['id']), 'type' => FR::MEMBERS_DIRECTORY_TYPE], |
| 122 | home_url() |
| 123 | )); |
| 124 | |
| 125 | $html = "<a target='_blank' class=\"add-new-h2\" href=\"$preview_url\">" . esc_html__('Live Preview', 'wp-user-avatar') . '</a>'; |
| 126 | |
| 127 | if ($echo === false) { |
| 128 | return $html; |
| 129 | } |
| 130 | |
| 131 | echo $html; |
| 132 | } |
| 133 | |
| 134 | /** |
| 135 | * Build the settings page structure. I.e tab, sidebar. |
| 136 | * |
| 137 | * @return mixed|void |
| 138 | */ |
| 139 | public function settings_admin_page_callback() |
| 140 | { |
| 141 | remove_all_actions('media_buttons'); |
| 142 | remove_all_filters('media_buttons_context'); |
| 143 | remove_all_filters('mce_buttons', 10); |
| 144 | remove_all_filters('mce_external_plugins', 10); |
| 145 | |
| 146 | add_action('media_buttons', 'media_buttons'); |
| 147 | |
| 148 | if ( ! empty($_GET['view']) && $_GET['view'] == 'add-new') { |
| 149 | echo '<script type="text/javascript">var pp_is_member_directory = true;</script>'; |
| 150 | |
| 151 | return AddNewForm::get_instance()->settings_admin_page(); |
| 152 | } |
| 153 | |
| 154 | $short_circuit = apply_filters('ppress_member_directory_settings_admin_page_short_circuit', false); |
| 155 | |
| 156 | if (false !== $short_circuit) return $short_circuit; |
| 157 | |
| 158 | add_filter('wp_cspa_main_content_area', array($this, 'wp_list_table'), 10, 2); |
| 159 | add_action('wp_cspa_before_closing_header', [$this, 'add_new_form_button']); |
| 160 | |
| 161 | $instance = Custom_Settings_Page_Api::instance(); |
| 162 | $instance->option_name(PPRESS_FORMS_DB_OPTION_NAME); |
| 163 | $instance->page_header($this->admin_page_title()); |
| 164 | $this->register_core_settings($instance, true); |
| 165 | echo '<div class="pp-form-listing pp-forms">'; |
| 166 | $instance->build(true); |
| 167 | echo '</div>'; |
| 168 | } |
| 169 | |
| 170 | public function add_new_form_button() |
| 171 | { |
| 172 | $url = esc_url(add_query_arg('view', 'add-new', PPRESS_MEMBER_DIRECTORIES_SETTINGS_PAGE)); |
| 173 | echo "<a class=\"add-new-h2\" href=\"$url\">" . esc_html__('Add New', 'wp-user-avatar') . '</a>'; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * @param string $content |
| 178 | * @param string $option_name settings Custom_Settings_Page_Api option name. |
| 179 | * |
| 180 | * @return string |
| 181 | */ |
| 182 | public function wp_list_table($content, $option_name) |
| 183 | { |
| 184 | if ($option_name != PPRESS_FORMS_DB_OPTION_NAME) return $content; |
| 185 | |
| 186 | $this->wplist_instance->prepare_items(FR::MEMBERS_DIRECTORY_TYPE); |
| 187 | |
| 188 | ob_start(); |
| 189 | |
| 190 | $this->wplist_instance->display(); |
| 191 | |
| 192 | return ob_get_clean(); |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * @return self |
| 197 | */ |
| 198 | public static function get_instance() |
| 199 | { |
| 200 | static $instance = null; |
| 201 | |
| 202 | if (is_null($instance)) { |
| 203 | $instance = new self(); |
| 204 | } |
| 205 | |
| 206 | return $instance; |
| 207 | } |
| 208 | } |