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