DragDropBuilder
4 years ago
EmailSettings
4 years ago
AbstractSettingsPage.php
4 years ago
AddNewForm.php
4 years ago
AdminFooter.php
5 years ago
ExtensionsSettingsPage.php
4 years ago
FormList.php
5 years ago
Forms.php
4 years ago
GeneralSettings.php
4 years ago
IDUserColumn.php
5 years ago
MailOptin.php
4 years ago
MemberDirectories.php
4 years ago
MembersDirectoryList.php
5 years ago
ToolsSettingsPage.php
4 years ago
index.php
5 years ago
MemberDirectories.php
246 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 $EditShortcodeMemberDirectoriesInstance; |
| 21 | protected $DragDropClassInstance; |
| 22 | |
| 23 | public function __construct() |
| 24 | { |
| 25 | add_action('ppress_register_menu_page', array($this, 'register_settings_page')); |
| 26 | add_action('ppress_admin_settings_page_member-directories', [$this, 'settings_admin_page_callback']); |
| 27 | add_action('ppress_admin_settings_page_add-new', [$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 | |
| 35 | public function admin_page_title() |
| 36 | { |
| 37 | $page_title = esc_html__('Member Directories', 'wp-user-avatar'); |
| 38 | |
| 39 | if (isset($_GET['page'], $_GET['view']) && $_GET['page'] == PPRESS_MEMBER_DIRECTORIES_SLUG) { |
| 40 | $page_title = esc_html__('Add Member Directory', 'wp-user-avatar'); |
| 41 | } |
| 42 | |
| 43 | if (isset($_GET['view'], $_GET['form-type']) && $_GET['form-type'] == FR::MEMBERS_DIRECTORY_TYPE) { |
| 44 | $page_title = esc_html__('Edit Member Directory', 'wp-user-avatar'); |
| 45 | } |
| 46 | |
| 47 | return $page_title; |
| 48 | } |
| 49 | |
| 50 | public function register_settings_page() |
| 51 | { |
| 52 | $hook = add_submenu_page( |
| 53 | PPRESS_SETTINGS_SLUG, |
| 54 | $this->admin_page_title() . ' - ProfilePress', |
| 55 | esc_html__('Member Directories', 'wp-user-avatar'), |
| 56 | 'manage_options', |
| 57 | PPRESS_MEMBER_DIRECTORIES_SLUG, |
| 58 | array($this, 'admin_page_callback') |
| 59 | ); |
| 60 | |
| 61 | add_action("load-$hook", array($this, 'screen_option')); |
| 62 | } |
| 63 | |
| 64 | public function default_header_menu() |
| 65 | { |
| 66 | return 'member-directories'; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Save screen option. |
| 71 | * |
| 72 | * @param string $status |
| 73 | * @param string $option |
| 74 | * @param string $value |
| 75 | * |
| 76 | * @return mixed |
| 77 | */ |
| 78 | public function set_screen($status, $option, $value) |
| 79 | { |
| 80 | return $value; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Screen options |
| 85 | */ |
| 86 | public function screen_option() |
| 87 | { |
| 88 | if (isset($_GET['page'], $_GET['view']) && strpos($_GET['view'], 'edit-shortcode') !== false) return; |
| 89 | |
| 90 | $args = [ |
| 91 | 'label' => esc_html__('Member Directories', 'wp-user-avatar'), |
| 92 | 'default' => 10, |
| 93 | 'option' => 'forms_per_page', |
| 94 | ]; |
| 95 | |
| 96 | add_screen_option('per_page', $args); |
| 97 | |
| 98 | if (isset($_GET['id']) || ppress_var($_GET, 'view') == 'add-new') { |
| 99 | add_filter('screen_options_show_screen', '__return_false'); |
| 100 | } |
| 101 | |
| 102 | $this->wplist_instance = MembersDirectoryList::get_instance(); |
| 103 | } |
| 104 | |
| 105 | public function live_form_preview_btn($echo = true) |
| 106 | { |
| 107 | if ( ! isset($_GET['view'])) return; |
| 108 | |
| 109 | $preview_url = esc_url(add_query_arg( |
| 110 | ['pp_preview_form' => absint($_GET['id']), 'type' => FR::MEMBERS_DIRECTORY_TYPE], |
| 111 | home_url() |
| 112 | )); |
| 113 | |
| 114 | $html = "<a target='_blank' class=\"add-new-h2\" href=\"$preview_url\">" . esc_html__('Live Preview', 'wp-user-avatar') . '</a>'; |
| 115 | |
| 116 | if ($echo === false) { |
| 117 | return $html; |
| 118 | } |
| 119 | |
| 120 | echo $html; |
| 121 | } |
| 122 | |
| 123 | public function no_form_exist_redirect($form_id, $form_type) |
| 124 | { |
| 125 | if ( ! FR::form_id_exist($form_id, $form_type)) { |
| 126 | wp_safe_redirect(add_query_arg('form-type', $form_type, PPRESS_FORMS_SETTINGS_PAGE)); |
| 127 | exit; |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | /** |
| 132 | * Build the settings page structure. I.e tab, sidebar. |
| 133 | * |
| 134 | * @return mixed|void |
| 135 | */ |
| 136 | public function settings_admin_page_callback() |
| 137 | { |
| 138 | remove_all_actions('media_buttons'); |
| 139 | remove_all_filters('media_buttons_context'); |
| 140 | remove_all_filters('mce_buttons', 10); |
| 141 | remove_all_filters('mce_external_plugins', 10); |
| 142 | |
| 143 | add_action('media_buttons', 'media_buttons'); |
| 144 | |
| 145 | if ( ! empty($_GET['view']) && $_GET['view'] == 'add-new') { |
| 146 | echo '<script type="text/javascript">var pp_is_member_directory = true;</script>'; |
| 147 | |
| 148 | return AddNewForm::get_instance()->settings_admin_page(); |
| 149 | } |
| 150 | |
| 151 | if ( ! empty($_GET['view'])) { |
| 152 | |
| 153 | $form_id = absint($_GET['id']); |
| 154 | |
| 155 | $page_header = $this->admin_page_title(); |
| 156 | |
| 157 | $shortcode_builder_page_header = sprintf( |
| 158 | '<div class="wrap ppSCB"><h2>%s %s</h2><form method="post">%s', |
| 159 | esc_html($page_header), |
| 160 | $this->live_form_preview_btn(false), |
| 161 | ppress_nonce_field() |
| 162 | ); |
| 163 | |
| 164 | if ($_GET['view'] == 'edit-shortcode-members-directory') { |
| 165 | Forms::get_instance()->no_form_exist_redirect($form_id, FR::MEMBERS_DIRECTORY_TYPE); |
| 166 | echo $shortcode_builder_page_header; |
| 167 | $this->EditShortcodeMemberDirectoriesInstance->edit_screen(); |
| 168 | echo '</form></div>'; |
| 169 | |
| 170 | return; |
| 171 | } |
| 172 | |
| 173 | add_filter('wp_cspa_settings_page_sidebar', [$this->DragDropClassInstance, 'sidebar_section']); |
| 174 | add_action('wp_cspa_before_closing_header', [$this, 'live_form_preview_btn']); |
| 175 | |
| 176 | add_action('wp_cspa_main_content_area', function ($content, $option_name) { |
| 177 | if ($option_name != 'pp_edit_form') return $content; |
| 178 | |
| 179 | if ($_GET['view'] == 'drag-drop-builder') { |
| 180 | ob_start(); |
| 181 | $this->DragDropClassInstance->admin_page(); |
| 182 | |
| 183 | return ob_get_clean(); |
| 184 | } |
| 185 | }, 10, 2); |
| 186 | |
| 187 | $instance = Custom_Settings_Page_Api::instance(); |
| 188 | $instance->option_name('pp_edit_form'); |
| 189 | $instance->add_wrap_classes('pp-dnd-form-builder-wrap'); |
| 190 | $instance->page_header($this->admin_page_title()); |
| 191 | $this->register_core_settings($instance); |
| 192 | |
| 193 | return $instance->build(); |
| 194 | } |
| 195 | |
| 196 | add_action('wp_cspa_main_content_area', array($this, 'wp_list_table'), 10, 2); |
| 197 | add_action('wp_cspa_before_closing_header', [$this, 'add_new_form_button']); |
| 198 | |
| 199 | $instance = Custom_Settings_Page_Api::instance(); |
| 200 | $instance->option_name(PPRESS_FORMS_DB_OPTION_NAME); |
| 201 | $instance->page_header($this->admin_page_title()); |
| 202 | $this->register_core_settings($instance, true); |
| 203 | echo '<div class="pp-form-listing pp-forms">'; |
| 204 | $instance->build(true); |
| 205 | echo '</div>'; |
| 206 | } |
| 207 | |
| 208 | public function add_new_form_button() |
| 209 | { |
| 210 | $url = esc_url(add_query_arg('view', 'add-new', PPRESS_MEMBER_DIRECTORIES_SETTINGS_PAGE)); |
| 211 | echo "<a class=\"add-new-h2\" href=\"$url\">" . esc_html__('Add New', 'wp-user-avatar') . '</a>'; |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * @param string $content |
| 216 | * @param string $option_name settings Custom_Settings_Page_Api option name. |
| 217 | * |
| 218 | * @return string |
| 219 | */ |
| 220 | public function wp_list_table($content, $option_name) |
| 221 | { |
| 222 | if ($option_name != PPRESS_FORMS_DB_OPTION_NAME) return $content; |
| 223 | |
| 224 | $this->wplist_instance->prepare_items(FR::MEMBERS_DIRECTORY_TYPE); |
| 225 | |
| 226 | ob_start(); |
| 227 | |
| 228 | $this->wplist_instance->display(); |
| 229 | |
| 230 | return ob_get_clean(); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * @return self |
| 235 | */ |
| 236 | public static function get_instance() |
| 237 | { |
| 238 | static $instance = null; |
| 239 | |
| 240 | if (is_null($instance)) { |
| 241 | $instance = new self(); |
| 242 | } |
| 243 | |
| 244 | return $instance; |
| 245 | } |
| 246 | } |