| @@ -5,8 +5,9 @@ | ||
| 5 | 5 | use Averta\WordPress\Utility\Escape; |
| 6 | 6 | use Averta\WordPress\Utility\JSON; |
| 7 | 7 | use Averta\WordPress\Utility\Plugin; |
| 8 | 8 | use Depicter\Security\CSRF; |
| 9 | +use Depicter\WordPress\Settings\Settings; | |
| 9 | 10 | |
| 10 | 11 | class DashboardPage |
| 11 | 12 | { |
| 12 | 13 | |
| @@ -22,8 +23,10 @@ | ||
| 22 | 23 | add_action( 'admin_menu', [ $this, 'registerPage' ] ); |
| 23 | 24 | add_action( 'admin_enqueue_scripts', [ $this, 'enqueueScripts' ] ); |
| 24 | 25 | add_action( 'admin_head', array( $this, 'disable_admin_notices' ) ); |
| 25 | 26 | add_action( 'admin_init', [ $this, 'externalPageRedirect' ] ); |
| 27 | + | |
| 28 | + $this->settingsPage(); | |
| 26 | 29 | } |
| 27 | 30 | |
| 28 | 31 | /** |
| 29 | 32 | * Register admin pages. |
| @@ -33,9 +36,9 @@ | ||
| 33 | 36 | public function registerPage() { |
| 34 | 37 | $this->hook_suffix = add_menu_page( |
| 35 | 38 | __('Depicter', 'depicter'), |
| 36 | 39 | __('Depicter', 'depicter'), |
| 37 | - 'manage_options', | |
| 40 | + 'access_depicter', | |
| 38 | 41 | self::PAGE_ID, |
| 39 | 42 | [ $this, 'render' ], // called to output the content for this page |
| 40 | 43 | \Depicter::core()->assets()->getUrl() . '/resources/images/svg/wp-logo.svg' |
| 41 | 44 | ); |
| @@ -43,9 +46,9 @@ | ||
| 43 | 46 | add_submenu_page( |
| 44 | 47 | self::PAGE_ID, |
| 45 | 48 | __( 'Dashboard', 'depicter' ), |
| 46 | 49 | __( 'Dashboard', 'depicter' ), |
| 47 | - 'manage_options', | |
| 50 | + 'access_depicter', | |
| 48 | 51 | self::PAGE_ID |
| 49 | 52 | ); |
| 50 | 53 | |
| 51 | 54 | add_submenu_page( |
| @@ -51,9 +54,9 @@ | ||
| 51 | 54 | add_submenu_page( |
| 52 | 55 | self::PAGE_ID, |
| 53 | 56 | __( 'Add New', 'depicter' ), |
| 54 | 57 | __( 'Add New', 'depicter' ), |
| 55 | - 'manage_options', | |
| 58 | + 'create_depicter', | |
| 56 | 59 | self::PAGE_ID . '-create-slider', |
| 57 | 60 | [ $this, 'externalPageRedirect' ] |
| 58 | 61 | ); |
| 59 | 62 | |
| @@ -60,9 +63,9 @@ | ||
| 60 | 63 | add_submenu_page( |
| 61 | 64 | self::PAGE_ID, |
| 62 | 65 | __( 'Support', 'depicter' ), |
| 63 | 66 | __( 'Support', 'depicter' ), |
| 64 | - 'manage_options', | |
| 67 | + 'access_depicter', | |
| 65 | 68 | self::PAGE_ID . '-goto-support', |
| 66 | 69 | [ $this, 'externalPageRedirect' ] |
| 67 | 70 | ); |
| 68 | 71 | |
| @@ -90,8 +93,31 @@ | ||
| 90 | 93 | } |
| 91 | 94 | } |
| 92 | 95 | |
| 93 | 96 | /** |
| 97 | + * Settings page markup | |
| 98 | + * | |
| 99 | + * @return void | |
| 100 | + */ | |
| 101 | + public function settingsPage() { | |
| 102 | + | |
| 103 | + $settings = new Settings(__('Settings', 'depicter'), 'depicter-settings'); | |
| 104 | + $settings->set_option_name('depicter_options'); | |
| 105 | + $settings->set_menu_parent_slug( self::PAGE_ID ); | |
| 106 | + | |
| 107 | + $settings->add_tab(__( 'General', 'depicter' )); | |
| 108 | + $settings->add_section( __( 'General Settings', 'depicter' ) ); | |
| 109 | + $settings->add_option('checkbox', [ | |
| 110 | + 'name' => 'always_load_assets', | |
| 111 | + 'label' => __( 'Load assets on all pages?', 'depicter' ), | |
| 112 | + 'description' => __( 'By default, Depicter will load corresponding JavaScript and CSS files on demand. but if you need to load assets on all pages, check this option. <br>( For example, if you plan to load Depicter via Ajax, you need to enable this option )', 'depicter' ), | |
| 113 | + ]); | |
| 114 | + | |
| 115 | + $settings->make(); | |
| 116 | + | |
| 117 | + } | |
| 118 | + | |
| 119 | + /** | |
| 94 | 120 | * Disable all admin notices in dashboard page |
| 95 | 121 | * |
| 96 | 122 | * @return void |
| 97 | 123 | */ |
| @@ -145,9 +171,9 @@ | ||
| 145 | 171 | wp_add_inline_script('depicter--dashboard', 'window.depicterEnv = '. JSON::encode( |
| 146 | 172 | [ |
| 147 | 173 | 'wpVersion' => $wp_version, |
| 148 | 174 | "scriptsPath" => \Depicter::core()->assets()->getUrl(). '/resources/scripts/dashboard/', |
| 149 | - 'clientKey' => \Depicter::options()->get( 'client_key', 'anon' ), | |
| 175 | + 'clientKey' => \Depicter::auth()->getClientKey(), | |
| 150 | 176 | 'csrfToken' => \Depicter::csrf()->getToken( CSRF::DASHBOARD_ACTION ), |
| 151 | 177 | 'updateInfo' => [ |
| 152 | 178 | 'from' => \Depicter::options()->get('version_previous') ?: null, |
| 153 | 179 | 'to' => \Depicter::options()->get('version') |
| @@ -157,16 +183,25 @@ | ||
| 157 | 183 | "pluginAPI" => admin_url( 'admin-ajax.php' ), |
| 158 | 184 | "editorPath" => \Depicter::editor()->getEditUrl( '__id__' ), |
| 159 | 185 | "documentPreviewPath" => \Depicter::editor()->getEditUrl( '__id__' ), |
| 160 | 186 | 'user' => [ |
| 161 | - 'tier' => \Depicter::options()->get('user_plan', 'free-user'), | |
| 187 | + 'tier' => \Depicter::auth()->getTier(), | |
| 162 | 188 | 'name' => Escape::html( $currentUser->display_name ), |
| 163 | 189 | 'email' => Escape::html( $currentUser->user_email ), |
| 164 | 190 | 'joinedNewsletter' => !! \Depicter::options()->get('has_subscribed') |
| 165 | 191 | ], |
| 192 | + 'activation' => [ | |
| 193 | + 'status' => \Depicter::auth()->getActivationStatus(), | |
| 194 | + 'errorMessage' => \Depicter::options()->get('activation_error_message', ''), | |
| 195 | + 'expiresAt' => \Depicter::options()->get('subscription_expires_at' , ''), | |
| 196 | + 'isNew' => isset( $_GET['depicter_upgraded'] ) | |
| 197 | + ], | |
| 166 | 198 | 'integrations' => [ |
| 167 | 199 | 'woocommerce' => Plugin::isActive( 'woocommerce/woocommerce.php' ) |
| 168 | - ] | |
| 200 | + ], | |
| 201 | + 'AIWizard' => [ | |
| 202 | + 'introVideoSrc' => 'https://www.youtube.com/embed/kdR9Jw0yWjU?rel=0' | |
| 203 | + ] | |
| 169 | 204 | ] |
| 170 | 205 | ), 'before' ); |
| 171 | 206 | |
| 172 | 207 | } |