base/model.php 0000666 00000001135 15214141735 0007276 0 ustar 00 get_css_file_name(); add_action( "elementor/css-file/{$name}/parse", [ $this, 'add_settings_css_rules' ] ); } /** * Save settings. * * Save settings to the database and update the CSS file. * * @since 2.8.0 * @access public * * @param array $settings Settings. * @param int $id Optional. Post ID. Default is `0`. */ public function save_settings( array $settings, $id = 0 ) { parent::save_settings( $settings, $id ); $css_file = $this->get_css_file_for_update( $id ); if ( $css_file ) { $css_file->update(); } } /** * Add settings CSS rules. * * Add new CSS rules to the settings manager. * * Fired by `elementor/css-file/{$name}/parse` action. * * @since 2.8.0 * @access public * * @param CSS_File $css_file The requested CSS file. * */ public function add_settings_css_rules( CSS_File $css_file ) { $model = $this->get_model_for_css_file( $css_file ); $css_file->add_controls_stack_style_rules( $model, $model->get_style_controls(), $model->get_settings(), [ '{{WRAPPER}}' ], [ $model->get_css_wrapper_selector() ] ); } } base/manager.php 0000666 00000020047 15214141735 0007613 0 ustar 00 get_name(); $ajax_manager->register_ajax_action( "save_{$name}_settings", [ $this, 'ajax_save_settings' ] ); } /** * Get model for config. * * Retrieve the model for settings configuration. * * @since 1.6.0 * @access public * @abstract * * @return Model The model object. */ abstract public function get_model_for_config(); /** * Get manager name. * * Retrieve settings manager name. * * @since 1.6.0 * @access public * @abstract */ abstract public function get_name(); /** * Get model. * * Retrieve the model for any given model ID. * * @since 1.6.0 * @access public * * @param int $id Optional. Model ID. Default is `0`. * * @return Model The model. */ final public function get_model( $id = 0 ) { if ( ! isset( $this->models_cache[ $id ] ) ) { $this->create_model( $id ); } return $this->models_cache[ $id ]; } /** * Ajax request to save settings. * * Save settings using an ajax request. * * @since 1.6.0 * @access public * * @param array $request Ajax request. * * @return array Ajax response data. */ final public function ajax_save_settings( $request ) { $data = $request['data']; $id = 0; if ( ! empty( $request['id'] ) ) { $id = $request['id']; } $this->ajax_before_save_settings( $data, $id ); $this->save_settings( $data, $id ); $settings_name = $this->get_name(); $success_response_data = []; /** * Settings success response data. * * Filters the success response data when saving settings using ajax. * * The dynamic portion of the hook name, `$settings_name`, refers to the settings name. * * @since 1.6.0 * @deprecated 2.0.0 Use `elementor/settings/{$settings_name}/success_response_data` filter. * * @param array $success_response_data Success response data. * @param int $id Settings ID. * @param array $data Settings data. */ $success_response_data = apply_filters_deprecated( "elementor/{$settings_name}/settings/success_response_data", [ $success_response_data, $id, $data ], '2.0.0', "elementor/settings/{$settings_name}/success_response_data" ); /** * Settings success response data. * * Filters the success response data when saving settings using ajax. * * The dynamic portion of the hook name, `$settings_name`, refers to the settings name. * * @since 2.0.0 * * @param array $success_response_data Success response data. * @param int $id Settings ID. * @param array $data Settings data. */ $success_response_data = apply_filters( "elementor/settings/{$settings_name}/success_response_data", $success_response_data, $id, $data ); return $success_response_data; } /** * Save settings. * * Save settings to the database. * * @since 1.6.0 * @access public * * @param array $settings Settings. * @param int $id Optional. Post ID. Default is `0`. */ public function save_settings( array $settings, $id = 0 ) { $special_settings = $this->get_special_settings_names(); $settings_to_save = $settings; foreach ( $special_settings as $special_setting ) { if ( isset( $settings_to_save[ $special_setting ] ) ) { unset( $settings_to_save[ $special_setting ] ); } } $this->save_settings_to_db( $settings_to_save, $id ); // Clear cache after save. if ( isset( $this->models_cache[ $id ] ) ) { unset( $this->models_cache[ $id ] ); } } /** * On Elementor init. * * Add editor template for the settings * * Fired by `elementor/init` action. * * @since 2.3.0 * @access public */ public function on_elementor_editor_init() { Plugin::$instance->common->add_template( $this->get_editor_template(), 'text' ); } /** * Get saved settings. * * Retrieve the saved settings from the database. * * @since 1.6.0 * @access protected * @abstract * * @param int $id Post ID. */ abstract protected function get_saved_settings( $id ); /** * Save settings to DB. * * Save settings to the database. * * @since 1.6.0 * @access protected * @abstract * * @param array $settings Settings. * @param int $id Post ID. */ abstract protected function save_settings_to_db( array $settings, $id ); /** * Get special settings names. * * Retrieve the names of the special settings that are not saved as regular * settings. Those settings have a separate saving process. * * @since 1.6.0 * @access protected * * @return array Special settings names. */ protected function get_special_settings_names() { return []; } /** * Ajax before saving settings. * * Validate the data before saving it and updating the data in the database. * * @since 1.6.0 * @access public * * @param array $data Post data. * @param int $id Post ID. */ public function ajax_before_save_settings( array $data, $id ) {} /** * Print the setting template content in the editor. * * Used to generate the control HTML in the editor using Underscore JS * template. The variables for the class are available using `data` JS * object. * * @since 1.6.0 * @access protected * * @param string $name Settings panel name. */ protected function print_editor_template_content( $name ) { ?> <# const tabs = elementor.config.settings..tabs; if ( Object.values( tabs ).length > 1 ) { #>
<# } #> models_cache[ $id ] = new $class_name( [ 'id' => $id, 'settings' => $this->get_saved_settings( $id ), ] ); } /** * Get editor template. * * Retrieve the final HTML for the editor. * * @since 1.6.0 * @access private * * @return string Settings editor template. */ private function get_editor_template() { $name = $this->get_name(); ob_start(); ?> __( 'Editor Preferences', 'elementor' ), ]; } /** * @since 2.8.0 * @access protected */ protected function _register_controls() { $this->start_controls_section( 'preferences', [ 'tab' => Controls_Manager::TAB_SETTINGS, 'label' => __( 'Preferences', 'elementor' ), ] ); $this->add_control( 'ui_theme', [ 'label' => __( 'UI Theme', 'elementor' ), 'type' => Controls_Manager::SELECT, 'description' => __( 'Set light or dark mode, or use Auto Detect to sync it with your OS setting.', 'elementor' ), 'default' => 'auto', 'options' => [ 'auto' => __( 'Auto Detect', 'elementor' ), 'light' => __( 'Light', 'elementor' ), 'dark' => __( 'Dark', 'elementor' ), ], ] ); $this->add_control( 'edit_buttons', [ 'label' => __( 'Editing Handles', 'elementor' ), 'type' => Controls_Manager::SWITCHER, 'description' => __( 'Show editing handles when hovering over the element edit button.', 'elementor' ), ] ); $this->add_control( 'lightbox_in_editor', [ 'label' => __( 'Enable Lightbox In Editor', 'elementor' ), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes', ] ); $this->end_controls_section(); } } editor-preferences/manager.php 0000666 00000002662 15214141735 0012471 0 ustar 00 get_model(); } /** * Get manager name. * * Retrieve settings manager name. * * @since 2.8.0 * @access public */ public function get_name() { return 'editorPreferences'; } /** * Get saved settings. * * Retrieve the saved settings from the database. * * @since 2.8.0 * @access protected * * @param int $id. * @return array * */ protected function get_saved_settings( $id ) { $settings = get_user_meta( get_current_user_id(), self::META_KEY, true ); if ( ! $settings ) { $settings = []; } return $settings; } /** * Save settings to DB. * * Save settings to the database. * * @param array $settings Settings. * @param int $id Post ID. * @since 2.8.0 * @access protected * */ protected function save_settings_to_db( array $settings, $id ) { update_user_meta( get_current_user_id(), self::META_KEY, $settings ); } } manager.php 0000666 00000010515 15214141735 0006700 0 ustar 00 get_name() ] = $manager; } /** * Get settings managers. * * Retrieve registered settings manager(s). * * If no parameter passed, it will retrieve all the settings managers. For * any given parameter it will retrieve a single settings manager if one * exist, or `null` otherwise. * * @since 1.6.0 * @access public * @static * * @param string $manager_name Optional. Settings manager name. Default is * null. * * @return Base\Manager|Base\Manager[] Single settings manager, if it exists, * null if it doesn't exists, or the all * the settings managers if no parameter * defined. */ public static function get_settings_managers( $manager_name = null ) { if ( $manager_name ) { if ( isset( self::$settings_managers[ $manager_name ] ) ) { return self::$settings_managers[ $manager_name ]; } return null; } return self::$settings_managers; } /** * Register default settings managers. * * Register builtin Elementor settings managers. * * @since 1.6.0 * @access private * @static */ private static function register_default_settings_managers() { foreach ( self::$builtin_settings_managers_names as $manager_name ) { $manager_class = __NAMESPACE__ . '\\' . ucfirst( $manager_name ) . '\Manager'; self::add_settings_manager( new $manager_class() ); } } /** * Get settings managers config. * * Retrieve the settings managers configuration. * * @since 1.6.0 * @access public * @static * * @return array The settings managers configuration. */ public static function get_settings_managers_config() { $config = []; $user_can = Plugin::instance()->role_manager->user_can( 'design' ); foreach ( self::$settings_managers as $name => $manager ) { $settings_model = $manager->get_model_for_config(); $tabs = $settings_model->get_tabs_controls(); if ( ! $user_can ) { unset( $tabs['style'] ); } $config[ $name ] = [ 'name' => $manager->get_name(), 'panelPage' => $settings_model->get_panel_page_settings(), 'controls' => $settings_model->get_controls(), 'tabs' => $tabs, 'settings' => $settings_model->get_settings(), ]; if ( $settings_model instanceof CSS_Model ) { $config[ $name ]['cssWrapperSelector'] = $settings_model->get_css_wrapper_selector(); } } return $config; } /** * Get settings frontend config. * * Retrieve the settings managers frontend configuration. * * @since 1.6.0 * @access public * @static * * @return array The settings managers frontend configuration. */ public static function get_settings_frontend_config() { $config = []; foreach ( self::$settings_managers as $name => $manager ) { $settings_model = $manager->get_model_for_config(); if ( $settings_model ) { $config[ $name ] = $settings_model->get_frontend_settings(); } } return $config; } /** * Run settings managers. * * Register builtin Elementor settings managers. * * @since 1.6.0 * @access public * @static */ public static function run() { self::register_default_settings_managers(); } } general/manager.php 0000666 00000010540 15214141735 0010313 0 ustar 00 add_panel_tabs(); } /** * Get manager name. * * Retrieve general settings manager name. * * @since 1.6.0 * @access public * * @return string Manager name. */ public function get_name() { return 'general'; } /** * Get model for config. * * Retrieve the model for settings configuration. * * @since 1.6.0 * @access public * * @return BaseModel The model object. */ public function get_model_for_config() { return $this->get_model(); } /** * Get saved settings. * * Retrieve the saved settings from the site options. * * @since 1.6.0 * @access protected * * @param int $id Post ID. * * @return array Saved settings. */ protected function get_saved_settings( $id ) { $model_controls = Model::get_controls_list(); $settings = []; foreach ( $model_controls as $tab_name => $sections ) { foreach ( $sections as $section_name => $section_data ) { foreach ( $section_data['controls'] as $control_name => $control_data ) { $saved_setting = get_option( $control_name, null ); if ( null !== $saved_setting ) { $settings[ $control_name ] = $saved_setting; } } } } return $settings; } /** * Get CSS file name. * * Retrieve CSS file name for the general settings manager. * * @since 1.6.0 * @access protected * @return string * * @return string CSS file name. */ protected function get_css_file_name() { return 'global'; } /** * Save settings to DB. * * Save general settings to the database, as site options. * * @since 1.6.0 * @access protected * * @param array $settings Settings. * @param int $id Post ID. */ protected function save_settings_to_db( array $settings, $id ) { $model_controls = Model::get_controls_list(); $one_list_settings = []; foreach ( $model_controls as $tab_name => $sections ) { foreach ( $sections as $section_name => $section_data ) { foreach ( $section_data['controls'] as $control_name => $control_data ) { if ( isset( $settings[ $control_name ] ) ) { $one_list_control_name = str_replace( 'elementor_', '', $control_name ); $one_list_settings[ $one_list_control_name ] = $settings[ $control_name ]; update_option( $control_name, $settings[ $control_name ] ); } else { delete_option( $control_name ); } } } } // Save all settings in one list for a future usage if ( ! empty( $one_list_settings ) ) { update_option( self::META_KEY, $one_list_settings ); } else { delete_option( self::META_KEY ); } } /** * Get model for CSS file. * * Retrieve the model for the CSS file. * * @since 1.6.0 * @access protected * * @param Base $css_file The requested CSS file. * * @return BaseModel The model object. */ protected function get_model_for_css_file( Base $css_file ) { return $this->get_model(); } /** * Get CSS file for update. * * Retrieve the CSS file before updating the it. * * @since 1.6.0 * @access protected * * @param int $id Post ID. * * @return Global_CSS The global CSS file object. */ protected function get_css_file_for_update( $id ) { return Global_CSS::create( 'global.css' ); } /** * Add panel tabs. * * Register new panel tab for the lightbox settings. * * @since 1.6.0 * @access private */ private function add_panel_tabs() { Controls_Manager::add_tab( self::PANEL_TAB_LIGHTBOX, __( 'Lightbox', 'elementor' ) ); } } general/model.php 0000666 00000020277 15214141735 0010011 0 ustar 00 __( 'Global Settings', 'elementor' ), ]; } /** * Get controls list. * * Retrieve the global settings model controls list. * * @since 1.6.0 * @access public * @static * * @return array Controls list. */ public static function get_controls_list() { return [ Controls_Manager::TAB_STYLE => [ 'style' => [ 'label' => __( 'Style', 'elementor' ), 'controls' => [ 'elementor_default_generic_fonts' => [ 'label' => __( 'Default Generic Fonts', 'elementor' ), 'type' => Controls_Manager::TEXT, 'default' => 'Sans-serif', 'description' => __( 'The list of fonts used if the chosen font is not available.', 'elementor' ), 'label_block' => true, ], 'elementor_container_width' => [ 'label' => __( 'Content Width', 'elementor' ) . ' (px)', 'type' => Controls_Manager::NUMBER, 'min' => 300, 'description' => __( 'Sets the default width of the content area (Default: 1140)', 'elementor' ), 'selectors' => [ '.elementor-section.elementor-section-boxed > .elementor-container' => 'max-width: {{VALUE}}px', ], ], 'elementor_space_between_widgets' => [ 'label' => __( 'Widgets Space', 'elementor' ) . ' (px)', 'type' => Controls_Manager::NUMBER, 'min' => 0, 'placeholder' => '20', 'description' => __( 'Sets the default space between widgets (Default: 20)', 'elementor' ), 'selectors' => [ '.elementor-widget:not(:last-child)' => 'margin-bottom: {{VALUE}}px', ], ], 'elementor_stretched_section_container' => [ 'label' => __( 'Stretched Section Fit To', 'elementor' ), 'type' => Controls_Manager::TEXT, 'placeholder' => 'body', 'description' => __( 'Enter parent element selector to which stretched sections will fit to (e.g. #primary / .wrapper / main etc). Leave blank to fit to page width.', 'elementor' ), 'label_block' => true, 'frontend_available' => true, ], 'elementor_page_title_selector' => [ 'label' => __( 'Page Title Selector', 'elementor' ), 'type' => Controls_Manager::TEXT, 'placeholder' => 'h1.entry-title', 'description' => __( 'Elementor lets you hide the page title. This works for themes that have "h1.entry-title" selector. If your theme\'s selector is different, please enter it above.', 'elementor' ), 'label_block' => true, ], ], ], ], Manager::PANEL_TAB_LIGHTBOX => [ 'lightbox' => [ 'label' => __( 'Lightbox', 'elementor' ), 'controls' => [ 'elementor_global_image_lightbox' => [ 'label' => __( 'Image Lightbox', 'elementor' ), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes', 'description' => __( 'Open all image links in a lightbox popup window. The lightbox will automatically work on any link that leads to an image file.', 'elementor' ), 'frontend_available' => true, ], 'elementor_lightbox_enable_counter' => [ 'label' => __( 'Counter', 'elementor' ), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes', 'frontend_available' => true, ], 'elementor_lightbox_enable_fullscreen' => [ 'label' => __( 'Fullscreen', 'elementor' ), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes', 'frontend_available' => true, ], 'elementor_lightbox_enable_zoom' => [ 'label' => __( 'Zoom', 'elementor' ), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes', 'frontend_available' => true, ], 'elementor_lightbox_enable_share' => [ 'label' => __( 'Share', 'elementor' ), 'type' => Controls_Manager::SWITCHER, 'default' => 'yes', 'frontend_available' => true, ], 'elementor_lightbox_title_src' => [ 'label' => __( 'Title', 'elementor' ), 'type' => Controls_Manager::SELECT, 'options' => [ '' => __( 'None', 'elementor' ), 'title' => __( 'Title', 'elementor' ), 'caption' => __( 'Caption', 'elementor' ), 'alt' => __( 'Alt', 'elementor' ), 'description' => __( 'Description', 'elementor' ), ], 'default' => 'title', 'frontend_available' => true, ], 'elementor_lightbox_description_src' => [ 'label' => __( 'Description', 'elementor' ), 'type' => Controls_Manager::SELECT, 'options' => [ '' => __( 'None', 'elementor' ), 'title' => __( 'Title', 'elementor' ), 'caption' => __( 'Caption', 'elementor' ), 'alt' => __( 'Alt', 'elementor' ), 'description' => __( 'Description', 'elementor' ), ], 'default' => 'description', 'frontend_available' => true, ], 'elementor_lightbox_color' => [ 'label' => __( 'Background Color', 'elementor' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ '.elementor-lightbox' => 'background-color: {{VALUE}}', ], ], 'elementor_lightbox_ui_color' => [ 'label' => __( 'UI Color', 'elementor' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ '.elementor-lightbox' => '--lightbox-ui-color: {{VALUE}}', ], ], 'elementor_lightbox_ui_color_hover' => [ 'label' => __( 'UI Hover Color', 'elementor' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ '.elementor-lightbox' => '--lightbox-ui-color-hover: {{VALUE}}', ], ], 'elementor_lightbox_text_color' => [ 'label' => __( 'Text Color', 'elementor' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ '.elementor-lightbox' => '--lightbox-text-color: {{VALUE}}', ], ], 'lightbox_icons_size' => [ 'label' => __( 'Toolbar Icons Size', 'elementor' ), 'type' => Controls_Manager::SLIDER, 'selectors' => [ '.elementor-lightbox' => '--lightbox-header-icons-size: {{SIZE}}{{UNIT}}', ], 'separator' => 'before', ], 'lightbox_slider_icons_size' => [ 'label' => __( 'Navigation Icons Size', 'elementor' ), 'type' => Controls_Manager::SLIDER, 'selectors' => [ '.elementor-lightbox' => '--lightbox-navigation-icons-size: {{SIZE}}{{UNIT}}', ], 'separator' => 'before', ], ], ], ], ]; } /** * Register model controls. * * Used to add new controls to the global settings model. * * @since 1.6.0 * @access protected */ protected function _register_controls() { $controls_list = self::get_controls_list(); foreach ( $controls_list as $tab_name => $sections ) { foreach ( $sections as $section_name => $section_data ) { $this->start_controls_section( $section_name, [ 'label' => $section_data['label'], 'tab' => $tab_name, ] ); foreach ( $section_data['controls'] as $control_name => $control_data ) { $this->add_control( $control_name, $control_data ); } $this->end_controls_section(); } } } } page/manager.php 0000666 00000020701 15214141735 0007612 0 ustar 00 editor->is_edit_mode() ) { return null; } if ( Plugin::$instance->editor->is_edit_mode() ) { $post_id = Plugin::$instance->editor->get_post_id(); $document = Plugin::$instance->documents->get_doc_or_auto_save( $post_id ); } else { $post_id = get_the_ID(); $document = Plugin::$instance->documents->get_doc_for_frontend( $post_id ); } if ( ! $document ) { return null; } $model = $this->get_model( $document->get_post()->ID ); if ( $document->is_autosave() ) { $model->set_settings( 'post_status', $document->get_main_post()->post_status ); } return $model; } /** * Ajax before saving settings. * * Validate the data before saving it and updating the data in the database. * * @since 1.6.0 * @access public * * @param array $data Post data. * @param int $id Post ID. * * @throws \Exception If invalid post returned using the `$id`. * @throws \Exception If current user don't have permissions to edit the post. */ public function ajax_before_save_settings( array $data, $id ) { $post = get_post( $id ); if ( empty( $post ) ) { throw new \Exception( 'Invalid post.', Exceptions::NOT_FOUND ); } if ( ! current_user_can( 'edit_post', $id ) ) { throw new \Exception( 'Access denied.', Exceptions::FORBIDDEN ); } // Avoid save empty post title. if ( ! empty( $data['post_title'] ) ) { $post->post_title = $data['post_title']; } if ( isset( $data['post_excerpt'] ) && post_type_supports( $post->post_type, 'excerpt' ) ) { $post->post_excerpt = $data['post_excerpt']; } if ( isset( $data['post_status'] ) ) { $this->save_post_status( $id, $data['post_status'] ); unset( $post->post_status ); } wp_update_post( $post ); // Check updated status if ( DB::STATUS_PUBLISH === get_post_status( $id ) ) { $autosave = wp_get_post_autosave( $post->ID ); if ( $autosave ) { wp_delete_post_revision( $autosave->ID ); } } if ( isset( $data['post_featured_image'] ) && post_type_supports( $post->post_type, 'thumbnail' ) ) { if ( empty( $data['post_featured_image']['id'] ) ) { delete_post_thumbnail( $post->ID ); } else { set_post_thumbnail( $post->ID, $data['post_featured_image']['id'] ); } } if ( Utils::is_cpt_custom_templates_supported() ) { $template = get_metadata( 'post', $post->ID, '_wp_page_template', true ); if ( isset( $data['template'] ) ) { $template = $data['template']; } if ( empty( $template ) ) { $template = 'default'; } // Use `update_metadata` in order to save also for revisions. update_metadata( 'post', $post->ID, '_wp_page_template', $template ); } } /** * @inheritDoc * * Override parent because the page setting moved to document.settings. */ protected function print_editor_template_content( $name ) { ?> <# const tabs = elementor.config.document.settings.tabs; if ( Object.values( tabs ).length > 1 ) { #> <# } #> get_post_id(); if ( $css_file instanceof Post_Preview ) { $autosave = Utils::get_post_autosave( $post_id ); if ( $autosave ) { $post_id = $autosave->ID; } } return $this->get_model( $post_id ); } /** * Get special settings names. * * Retrieve the names of the special settings that are not saved as regular * settings. Those settings have a separate saving process. * * @since 1.6.0 * @access protected * * @return array Special settings names. */ protected function get_special_settings_names() { return [ 'id', 'post_title', 'post_status', 'template', 'post_excerpt', 'post_featured_image', ]; } /** * @since 2.0.0 * @access public * * @param $post_id * @param $status */ public function save_post_status( $post_id, $status ) { $parent_id = wp_is_post_revision( $post_id ); if ( $parent_id ) { // Don't update revisions post-status return; } $parent_id = $post_id; $post = get_post( $parent_id ); $allowed_post_statuses = get_post_statuses(); if ( isset( $allowed_post_statuses[ $status ] ) ) { $post_type_object = get_post_type_object( $post->post_type ); if ( 'publish' !== $status || current_user_can( $post_type_object->cap->publish_posts ) ) { $post->post_status = $status; } } wp_update_post( $post ); } } page/model.php 0000666 00000007552 15214141735 0007311 0 ustar 00 post = get_post( $data['id'] ); if ( ! $this->post ) { $this->post = new \WP_Post( (object) [] ); } if ( wp_is_post_revision( $this->post->ID ) ) { $this->post_parent = get_post( $this->post->post_parent ); } else { $this->post_parent = $this->post; } parent::__construct( $data ); } /** * Get model name. * * Retrieve page settings model name. * * @since 1.6.0 * @access public * * @return string Model name. */ public function get_name() { return 'page-settings'; } /** * Get model unique name. * * Retrieve page settings model unique name. * * @since 1.6.0 * @access public * * @return string Model unique name. */ public function get_unique_name() { return $this->get_name() . '-' . $this->post->ID; } /** * Get CSS wrapper selector. * * Retrieve the wrapper selector for the page settings model. * * @since 1.6.0 * @access public * * @return string CSS wrapper selector. */ public function get_css_wrapper_selector() { $document = Plugin::$instance->documents->get( $this->post_parent->ID ); return $document->get_css_wrapper_selector(); } /** * Get panel page settings. * * Retrieve the panel setting for the page settings model. * * @since 1.6.0 * @access public * * @return array { * Panel settings. * * @type string $title The panel title. * } */ public function get_panel_page_settings() { $document = Plugin::$instance->documents->get( $this->post->ID ); return [ /* translators: %s: Document title */ 'title' => sprintf( __( '%s Settings', 'elementor' ), $document::get_title() ), ]; } /** * On export post meta. * * When exporting data, check if the post is not using page template and * exclude it from the exported Elementor data. * * @since 1.6.0 * @access public * * @param array $element_data Element data. * * @return array Element data to be exported. */ public function on_export( $element_data ) { if ( ! empty( $element_data['settings']['template'] ) ) { /** * @var \Elementor\Modules\PageTemplates\Module $page_templates_module */ $page_templates_module = Plugin::$instance->modules_manager->get_modules( 'page-templates' ); $is_elementor_template = ! ! $page_templates_module->get_template_path( $element_data['settings']['template'] ); if ( ! $is_elementor_template ) { unset( $element_data['settings']['template'] ); } } return $element_data; } /** * Register model controls. * * Used to add new controls to the page settings model. * * @since 1.6.0 * @access protected */ protected function _register_controls() { // Check if it's a real model, or abstract (for example - on import ) if ( $this->post->ID ) { $document = Plugin::$instance->documents->get_doc_or_auto_save( $this->post->ID ); if ( $document ) { $controls = $document->get_controls(); foreach ( $controls as $control_id => $args ) { $this->add_control( $control_id, $args ); } } } } } validations.php 0000666 00000003177 15214147454 0007615 0 ustar 00 files_manager->clear_cache(); return $input; } } controls.php 0000666 00000015410 15214147454 0007134 0 ustar 00 '', 'attributes' => [], 'std' => '', 'desc' => '', ]; $field = array_merge( $defaults, $field ); $method_name = $field['type']; if ( ! method_exists( __CLASS__, $method_name ) ) { $method_name = 'text'; } self::$method_name( $field ); } /** * Render text control. * * Generates the final HTML for text controls. * * @since 2.0.0 * @access private * @static * * @param array $field Field data. */ private static function text( array $field ) { if ( empty( $field['attributes']['class'] ) ) { $field['attributes']['class'] = 'regular-text'; } $attributes = Utils::render_html_attributes( $field['attributes'] ); ?> /> $option_value ) : ?>' . $intro_text . '
'; echo $intro_text; }, 'fields' => [ 'rollback' => [ 'label' => __( 'Rollback Version', 'elementor' ), 'field_args' => [ 'type' => 'raw_html', 'html' => sprintf( $rollback_html . '%s', wp_nonce_url( admin_url( 'admin-post.php?action=elementor_rollback&version=VERSION' ), 'elementor_rollback' ), __( 'Reinstall', 'elementor' ) ), 'desc' => '' . __( 'Warning: Please backup your database before making the rollback.', 'elementor' ) . '', ], ], ], ], 'beta' => [ 'label' => __( 'Become a Beta Tester', 'elementor' ), 'callback' => function() { $intro_text = __( 'Turn-on Beta Tester, to get notified when a new beta version of Elementor or Elementor Pro is available. The Beta version will not install automatically. You always have the option to ignore it.', 'elementor' ); $intro_text = '' . $intro_text . '
'; $newsletter_opt_in_text = sprintf( __( 'Click here to join our first-to-know email updates.', 'elementor' ), '#' ); echo $intro_text; echo $newsletter_opt_in_text; }, 'fields' => [ 'beta' => [ 'label' => __( 'Beta Tester', 'elementor' ), 'field_args' => [ 'type' => 'select', 'default' => 'no', 'options' => [ 'no' => __( 'Disable', 'elementor' ), 'yes' => __( 'Enable', 'elementor' ), ], 'desc' => '' . __( 'Please Note: We do not recommend updating to a beta version on production sites.', 'elementor' ) . '', ], ], ], ], ], ], ]; } /** * Get tools page title. * * Retrieve the title for the tools page. * * @since 1.5.0 * @access protected * * @return string Tools page title. */ protected function get_page_title() { return __( 'Tools', 'elementor' ); } } class-ld-settings-pages.php 0000666 00000041130 15214240575 0011722 0 ustar 00 string * * @var string $settings_page_title */ protected $settings_page_title = ''; /** * Title for tab string * * @var string $settings_tab_title */ protected $settings_tab_title = ''; /** * Priority for tab * * @var integer $settings_tab_priority */ protected $settings_tab_priority = 30; /** * The number of columns to show. Most admin screens will be 2. But we set to 1 for the initial. * * @var integer $settings_columns */ protected $settings_columns = 2; /** * Wether to show the Submit metabox. * * @var boolean $show_submit_meta */ protected $show_submit_meta = true; /** * Wether to show the Quick Links metabox. * * @var boolean $show_quick_links_meta */ protected $show_quick_links_meta = true; /** * Wether to show wrap all settings in a . * * @var boolean $settings_form_wrap */ protected $settings_form_wrap = true; /** * Public constructor for class */ public function __construct() { global $learndash_pages; add_action( 'admin_init', array( $this, 'admin_init' ) ); add_action( 'admin_menu', array( $this, 'admin_menu' ) ); add_action( 'learndash_admin_tabs_set', array( $this, 'admin_tabs' ), 10 ); if ( empty( $this->settings_tab_title ) ) { $this->settings_tab_title = $this->settings_page_title; } if ( ( ! empty( $this->settings_page_id ) ) && ( ! isset( $learndash_pages[ $this->settings_page_id ] ) ) ) { $learndash_pages[] = $this->settings_page_id; } } /** * Function to get a specific setting page instance. * * @since 2.4.0 * * @param string $page_key Page key to get instance of. * * @return object page instance */ final public static function get_page_instance( $page_key = '' ) { if ( ! empty( $page_key ) ) { if ( isset( self::$_instances[ $page_key ] ) ) { return self::$_instances[ $page_key ]; } } } /** * Function to set/add setting page to instances array. * * @since 2.4.0 */ final public static function add_page_instance() { $section_class = get_called_class(); if ( ! isset( self::$_instances[ $section_class ] ) ) { self::$_instances[ $section_class ] = new $section_class(); } } /** * Action hook to handle admin_init processing from WP. */ public function admin_init() { do_action( 'learndash_settings_page_init', $this->settings_page_id ); if ( true === $this->show_submit_meta ) { $submit_obj = new LearnDash_Settings_Section_Side_Submit( array( 'settings_screen_id' => $this->settings_screen_id, 'settings_page_id' => $this->settings_page_id, ) ); } if ( true === $this->show_quick_links_meta ) { $ql_obj = new LearnDash_Settings_Section_Side_Quick_Links( array( 'settings_screen_id' => $this->settings_screen_id, 'settings_page_id' => $this->settings_page_id, ) ); } } /** * Action hook to handle admin_menu processing from WP. */ public function admin_menu() { if ( ! $this->settings_screen_id ) { $this->settings_screen_id = add_submenu_page( $this->parent_menu_page_url, $this->settings_page_title, $this->settings_page_title, $this->menu_page_capability, $this->settings_page_id, array( $this, 'show_settings_page' ) ); } add_action( 'load-' . $this->settings_screen_id, array( $this, 'load_settings_page' ) ); } /** * Action hook to handle admin_tabs processing from LearnDash. * * @param string $admin_menu_section Current admin menu section. */ public function admin_tabs( $admin_menu_section ) { if ( $admin_menu_section === $this->parent_menu_page_url ) { learndash_add_admin_tab_item( $this->parent_menu_page_url, array( 'id' => $this->settings_screen_id, 'link' => add_query_arg( array( 'page' => $this->settings_page_id ), 'admin.php' ), 'cap' => $this->menu_page_capability, 'name' => ! empty( $this->settings_tab_title ) ? $this->settings_tab_title : $this->settings_page_title, ), $this->settings_tab_priority ); } } /** * Action hook to handle current settings page load. */ public function load_settings_page() { global $learndash_assets_loaded; if ( defined( 'LEARNDASH_SETTINGS_SECTION_TYPE' ) && ( 'metabox' === LEARNDASH_SETTINGS_SECTION_TYPE ) ) { wp_enqueue_script( 'common' ); wp_enqueue_script( 'wp-lists' ); wp_enqueue_script( 'postbox' ); do_action( 'learndash_add_meta_boxes', $this->settings_screen_id ); add_action( 'admin_footer-' . $this->settings_screen_id, array( $this, 'load_footer_scripts' ) ); add_filter( 'screen_layout_columns', array( $this, 'screen_layout_column' ), 10, 2 ); } wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_media(); wp_enqueue_style( 'learndash_style', LEARNDASH_LMS_PLUGIN_URL . 'assets/css/style' . leardash_min_asset() . '.css', array(), LEARNDASH_SCRIPT_VERSION_TOKEN ); wp_style_add_data( 'learndash_style', 'rtl', 'replace' ); $learndash_assets_loaded['styles']['learndash_style'] = __FUNCTION__; wp_enqueue_style( 'sfwd-module-style', LEARNDASH_LMS_PLUGIN_URL . 'assets/css/sfwd_module' . leardash_min_asset() . '.css', array(), LEARNDASH_SCRIPT_VERSION_TOKEN ); wp_style_add_data( 'sfwd-module-style', 'rtl', 'replace' ); $learndash_assets_loaded['styles']['sfwd-module-style'] = __FUNCTION__; wp_enqueue_script( 'sfwd-module-script', LEARNDASH_LMS_PLUGIN_URL . 'assets/js/sfwd_module' . leardash_min_asset() . '.js', array( 'jquery' ), LEARNDASH_SCRIPT_VERSION_TOKEN, true ); $learndash_assets_loaded['scripts']['sfwd-module-script'] = __FUNCTION__; wp_localize_script( 'sfwd-module-script', 'sfwd_data', array() ); learndash_admin_settings_page_assets(); if ( isset( $_GET['ld_reset_metaboxes'] ) ) { delete_user_meta( get_current_user_id(), 'closedpostboxes_' . $this->settings_screen_id ); delete_user_meta( get_current_user_id(), 'metaboxhidden_' . $this->settings_screen_id ); delete_user_meta( get_current_user_id(), 'meta-box-order_' . $this->settings_screen_id ); } do_action( 'learndash-settings-page-load', $this->settings_screen_id, $this->settings_page_id ); } /** * Action hook to handle current settings page layout columns. * * @param integer $columns Number of columns to show. * @param Object $screen Current screen object. * * @return integer $columns */ public function screen_layout_column( $columns = false, $screen_id = '' ) { if ( $screen_id == $this->settings_screen_id ) { $columns[ $screen_id ] = $this->settings_columns; } /** * Add this filter to override the get user option logic. This is to force * the screen layout option for user who don't have this defined. * * @since 2.6.0 */ add_filter( "get_user_option_screen_layout_{$screen_id}", function( $option_value = '', $option_key = '' ) { if ( "screen_layout_{$this->settings_screen_id}" === $option_key ) { $option_value = $this->settings_columns; } return $option_value; }, 1, 2 ); return $columns; } /** * Action hook to handle footer JS/CSS added footer */ public function load_footer_scripts() { ?> settings_screen_id, $this->settings_page_id ); } /** * Fucntion to handle showing of Settings page. This is the main function for all visible * output. Extending classes can implement its own function. */ public function show_settings_page() { if ( defined( 'LEARNDASH_SETTINGS_SECTION_TYPE' ) && ( 'metabox' === LEARNDASH_SETTINGS_SECTION_TYPE ) ) { ?>' . esc_html__( 'You have errors on the following settings', 'learndash' ) . '
' . __( 'Warning: This plugin has not been tested with your current version of WordPress.', 'default' ) . '
' . __( 'Warning: This plugin has not been marked as compatible with your version of WordPress.', 'default' ) . '
" . esc_html__( 'buy', 'learndash' ) . '' ); ?>
time_to_recheck() ) { $license_status = $updater->getRemote_license(); /** * NOTE: The getRemote_license() does not update the option. * So we need to do it. And it needs to be set as an array structure. */ update_option( 'nss_plugin_remote_license_sfwd_lms', array( 'value' => $license_status ) ); // Then re-update the licens using new utility function. // Plus this provides simpler true/false boolean. $license_status = is_learndash_license_valid(); } } $this->license_info['license'] = $license; $this->license_info['email'] = $email; $this->license_info['status'] = $license_status; } } } } /** * Utility function to maybe display the Bootcamp * * @since 3.0.0 * * @param $toggle_state string Option value. * * @return string */ public function maybe_display_bootcamp( $toggle_state ) { if ( ! $toggle_state || 'show' === $toggle_state ) { return 'block'; } else { return 'none'; } } /** * Custom display function for page content. * * @since 3.0.0 */ public function show_settings_page() { $toggle_state = get_option( 'learndash_bootcamp_toggle_state' ); $this->get_feeds(); if ( learndash_is_admin_user() ) : $this->check_and_update_license(); endif; ?>/%s/ page.", 'placeholders: courses, courses (URL slug)', 'learndash' ) ), learndash_get_custom_label_lower( 'courses' ), LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Section_Permalinks', 'courses' ) );
parent::__construct();
}
function init_shortcodes_section_fields() {
$this->shortcodes_option_fields = array(
'orderby' => array(
'id' => $this->shortcodes_section_key . '_orderby',
'name' => 'orderby',
'type' => 'select',
'label' => esc_html__( 'Order by', 'learndash' ),
'help_text' => wp_kses_post( __( 'See the full list of available orderby options here.', 'learndash' ) ),
'value' => 'ID',
'options' => array(
'ID' => esc_html__('ID - Order by post id. (default)', 'learndash'),
'title' => esc_html__('Title - Order by post title', 'learndash'),
'date' => esc_html__('Date - Order by post date', 'learndash'),
'menu_order' => esc_html__('Menu - Order by Page Order Value', 'learndash')
)
),
'order' => array(
'id' => $this->shortcodes_section_key . '_order',
'name' => 'order',
'type' => 'select',
'label' => esc_html__( 'Order', 'learndash' ),
'help_text' => esc_html__( 'Order', 'learndash' ),
'value' => 'ID',
'options' => array(
'' => esc_html__('DESC - highest to lowest values (default)', 'learndash'),
'ASC' => esc_html__('ASC - lowest to highest values', 'learndash'),
)
),
'num' => array(
'id' => $this->shortcodes_section_key . '_num',
'name' => 'num',
'type' => 'number',
'label' => sprintf( esc_html_x('%s Per Page', 'placeholders: courses', 'learndash' ), LearnDash_Custom_Label::get_label( 'courses' ) ),
'help_text' => sprintf( esc_html_x( '%s per page. Default is %d. Set to zero for all.', 'placeholders: courses, default per page', 'learndash' ), LearnDash_Custom_Label::get_label( 'courses' ), LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Section_General_Per_Page', 'per_page' ) ),
'value' => '',
'class' => 'small-text',
'attrs' => array(
'min' => 0,
'step' => 1
)
),
'mycourses' => array(
'id' => $this->shortcodes_section_key . '_mycourses',
'name' => 'mycourses',
'type' => 'select',
'label' => sprintf( esc_html_x( 'My %s', 'placeholder: Courses', 'learndash'), LearnDash_Custom_Label::get_label( 'courses' ) ),
'help_text' => sprintf( esc_html_x( 'show current user\'s %s.', 'placeholders: courses', 'learndash' ), learndash_get_custom_label_lower( 'courses' ) ),
'value' => '',
'options' => array(
'' => sprintf( esc_html_x('Show All %s (default)', 'placeholders: courses', 'learndash'), learndash_get_custom_label_lower( 'Courses' ) ),
'enrolled' => sprintf( esc_html_x('Show Enrolled %s only', 'placeholders: courses', 'learndash' ), learndash_get_custom_label_lower( 'Courses' ) ),
'not-enrolled' => sprintf( esc_html_x('Show not-Enrolled %s only', 'placeholders: courses', 'learndash' ), learndash_get_custom_label_lower( 'Courses' ) ),
)
),
'status' => array(
'id' => $this->shortcodes_section_key . '_status',
'name' => 'status',
'type' => 'multiselect',
'label' => sprintf( esc_html_x( 'All %s Status', 'placeholder: Course', 'learndash'), LearnDash_Custom_Label::get_label( 'course' ) ),
'help_text' => sprintf( esc_html_x( 'filter %s by status.', 'placeholders: courses', 'learndash' ), learndash_get_custom_label_lower( 'courses' ) ),
'value' => array( 'not_started', 'in_progress', 'completed' ),
'options' => array(
//'' => esc_html__('All', 'learndash'),
'not_started' => esc_html__( 'Not Started', 'learndash' ),
'in_progress' => esc_html__( 'In Progress', 'learndash' ),
'completed' => esc_html__('Completed', 'learndash' ),
),
//'parent_setting' => 'mycourses',
),
'show_content' => array(
'id' => $this->shortcodes_section_key . 'show_content',
'name' => 'show_content',
'type' => 'select',
'label' => sprintf( esc_html_x('Show %s Content', 'placeholder: Course', 'learndash'), LearnDash_Custom_Label::get_label( 'course' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s content.', 'placeholders: course', 'learndash' ), learndash_get_custom_label_lower( 'course' ) ),
'value' => 'true',
'options' => array(
'' => esc_html__('Yes (default)', 'learndash'),
'false' => esc_html__('No', 'learndash'),
)
),
'show_thumbnail' => array(
'id' => $this->shortcodes_section_key . '_show_thumbnail',
'name' => 'show_thumbnail',
'type' => 'select',
'label' => sprintf( esc_html_x('Show %s Thumbnail', 'placeholder: Course', 'learndash'), LearnDash_Custom_Label::get_label( 'course' ) ),
'help_text' => sprintf( esc_html_x( 'shows a %s thumbnail.', 'placeholders: course', 'learndash' ), learndash_get_custom_label_lower( 'course' ) ),
'value' => 'true',
'options' => array(
'' => esc_html__('Yes (default)', 'learndash'),
'false' => esc_html__('No', 'learndash'),
)
),
);
if ( defined( 'LEARNDASH_COURSE_GRID_FILE' ) ) {
$this->shortcodes_option_fields['col'] = array(
'id' => $this->shortcodes_section_key . '_col',
'name' => 'col',
'type' => 'number',
'label' => esc_html__('Columns','learndash'),
'help_text' => sprintf( esc_html_x( 'number of columns to show when using %s grid addon', 'placeholders: course', 'learndash' ), learndash_get_custom_label_lower( 'course' ) ),
'value' => '',
'class' => 'small-text'
);
}
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Courses_Taxonomies', 'ld_course_category' ) == 'yes') {
$this->shortcodes_option_fields['course_category_name'] = array(
'id' => $this->shortcodes_section_key . 'course_category_name',
'name' => 'course_category_name',
'type' => 'text',
'label' => sprintf( esc_html_x('%s Category Slug', 'placeholder: Course', 'learndash'), LearnDash_Custom_Label::get_label( 'course' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned category slug.', 'placeholders: courses', 'learndash' ), learndash_get_custom_label_lower( 'courses' ) ),
'value' => '',
);
$this->shortcodes_option_fields['course_cat'] = array(
'id' => $this->shortcodes_section_key . 'course_cat',
'name' => 'course_cat',
'type' => 'number',
'label' => sprintf( esc_html_x('%s Category ID', 'placeholder: Course', 'learndash'), LearnDash_Custom_Label::get_label( 'course' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned category id.', 'placeholders: courses', 'learndash' ), learndash_get_custom_label_lower( 'courses' ) ),
'value' => '',
'class' => 'small-text'
);
$this->shortcodes_option_fields['course_categoryselector'] = array(
'id' => $this->shortcodes_section_key . 'course_categoryselector',
'name' => 'course_categoryselector',
'type' => 'checkbox',
'label' => sprintf( esc_html_x('%s Category Selector', 'placeholder: Course', 'learndash'), LearnDash_Custom_Label::get_label( 'course' ) ),
'help_text' => sprintf( esc_html_x( 'shows a %s category dropdown.', 'placeholders: course', 'learndash' ), learndash_get_custom_label_lower( 'course' ) ),
'value' => '',
'options' => array(
'true' => esc_html__('Yes', 'learndash'),
)
);
}
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Courses_Taxonomies', 'ld_course_tag' ) == 'yes') {
$this->shortcodes_option_fields['course_tag'] = array(
'id' => $this->shortcodes_section_key . 'course_tag',
'name' => 'course_tag',
'type' => 'text',
'label' => sprintf( esc_html_x( '%s Tag Slug', 'placeholder: Course', 'learndash'), LearnDash_Custom_Label::get_label( 'course' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned tag slug.', 'placeholders: courses', 'learndash' ), learndash_get_custom_label_lower( 'courses' ) ),
'value' => '',
);
$this->shortcodes_option_fields['course_tag_id'] = array(
'id' => $this->shortcodes_section_key . 'course_tag_id',
'name' => 'course_tag_id',
'type' => 'number',
'label' => sprintf( esc_html_x('%s Tag ID', 'placeholder: Course', 'learndash'), LearnDash_Custom_Label::get_label( 'course' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned tag id.', 'placeholders: courses', 'learndash' ), learndash_get_custom_label_lower( 'courses' ) ),
'value' => '',
'class' => 'small-text'
);
}
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Courses_Taxonomies', 'wp_post_category' ) == 'yes') {
$this->shortcodes_option_fields['category_name'] = array(
'id' => $this->shortcodes_section_key . 'category_name',
'name' => 'category_name',
'type' => 'text',
'label' => esc_html__('WP Category Slug', 'learndash'),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned WP category slug.', 'placeholders: courses', 'learndash' ), learndash_get_custom_label_lower( 'courses' ) ),
'value' => '',
);
$this->shortcodes_option_fields['cat'] = array(
'id' => $this->shortcodes_section_key . 'cat',
'name' => 'cat',
'type' => 'number',
'label' => esc_html__('WP Category ID', 'learndash'),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned WP category id.', 'placeholders: courses', 'learndash' ), learndash_get_custom_label_lower( 'courses' ) ),
'value' => '',
'class' => 'small-text'
);
$this->shortcodes_option_fields['categoryselector'] = array(
'id' => $this->shortcodes_section_key . 'categoryselector',
'name' => 'categoryselector',
'type' => 'checkbox',
'label' => esc_html__('WP Category Selector', 'learndash'),
'help_text' => esc_html__( 'shows a WP category dropdown.', 'learndash' ),
'value' => '',
'options' => array(
'true' => esc_html__('Yes', 'learndash'),
)
);
}
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Courses_Taxonomies', 'wp_post_tag' ) == 'yes') {
$this->shortcodes_option_fields['tag'] = array(
'id' => $this->shortcodes_section_key . 'tag',
'name' => 'tag',
'type' => 'text',
'label' => esc_html__( 'WP Tag Slug', 'learndash'),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned WP tag slug.', 'placeholders: courses', 'learndash' ), learndash_get_custom_label_lower( 'courses' ) ),
'value' => '',
);
$this->shortcodes_option_fields['tag_id'] = array(
'id' => $this->shortcodes_section_key . 'tag_id',
'name' => 'tag_id',
'type' => 'number',
'label' => esc_html__('WP Tag ID', 'learndash'),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned WP tag id.', 'placeholders: courses', 'learndash' ), learndash_get_custom_label_lower( 'courses' ) ),
'value' => '',
'class' => 'small-text'
);
}
$this->shortcodes_option_fields = apply_filters( 'learndash_settings_fields', $this->shortcodes_option_fields, $this->shortcodes_section_key );
parent::init_shortcodes_section_fields();
}
function show_shortcodes_section_footer_extra() {
?>
fields_args = $fields_args;
$this->shortcodes_section_key = 'ld_certificate';
$this->shortcodes_section_title = esc_html__( 'Certificate', 'learndash' );
$this->shortcodes_section_type = 2;
$this->shortcodes_section_description = esc_html__( 'This shortcode shows a Certificate download link.', 'learndash' );
parent::__construct();
}
function init_shortcodes_section_fields() {
$this->shortcodes_option_fields = array(
'course_id' => array(
'id' => $this->shortcodes_section_key . '_course_id',
'name' => 'course_id',
'type' => 'number',
'label' => sprintf(
// translators: placeholder: Course.
esc_html_x( '%s ID', 'placeholder: Course', 'learndash' ),
LearnDash_Custom_Label::get_label( 'course' )
),
'help_text' => sprintf(
// translators: placeholders: Course, Course.
esc_html_x( 'Enter single %1$s ID. Leave blank for current %2$s.', 'placeholders: Course, Course', 'learndash' ),
LearnDash_Custom_Label::get_label( 'course' ),
LearnDash_Custom_Label::get_label( 'course' )
),
'value' => '',
//'required' => 'required',
'class' => 'small-text',
),
'quiz_id' => array(
'id' => $this->shortcodes_section_key . '_quiz_id',
'name' => 'quiz_id',
'type' => 'number',
'label' => sprintf(
// translators: placeholder: Quiz.
esc_html_x( '%s ID', 'placeholder: Quiz', 'learndash' ),
LearnDash_Custom_Label::get_label( 'quiz' )
),
'help_text' => sprintf(
// translators: placeholders: Quiz, Quiz.
esc_html_x( 'Enter single %1$s ID. Leave blank for current %2$s.', 'placeholders: Quiz, Quiz', 'learndash' ),
LearnDash_Custom_Label::get_label( 'quiz' ),
LearnDash_Custom_Label::get_label( 'quiz' )
),
'value' => '',
'class' => 'small-text',
),
'user_id' => array(
'id' => $this->shortcodes_section_key . '_user_id',
'name' => 'user_id',
'type' => 'number',
'label' => esc_html__( 'User ID', 'learndash' ),
'help_text' => esc_html__( 'Enter specific User ID. Leave blank for current User.', 'learndash' ),
'value' => '',
'class' => 'small-text',
),
'label' => array(
'id' => $this->shortcodes_section_key . '_label',
'name' => 'label',
'type' => 'text',
'label' => esc_html__( 'Label', 'learndash' ),
'help_text' => esc_html__( 'Label for link shown to user', 'learndash' ),
'value' => '',
),
'class' => array(
'id' => $this->shortcodes_section_key . '_class',
'name' => 'class',
'type' => 'text',
'label' => esc_html__( 'HTML Class', 'learndash' ),
'help_text' => esc_html__( 'HTML class for link element', 'learndash' ),
'value' => '',
),
'context' => array(
'id' => $this->shortcodes_section_key . '_context',
'name' => 'context',
'type' => 'text',
'label' => esc_html__( 'Context', 'learndash' ),
'help_text' => esc_html__( 'User defined value to be passed into shortcode handler', 'learndash' ),
'value' => '',
),
'callback' => array(
'id' => $this->shortcodes_section_key . '_callback',
'name' => 'callback',
'type' => 'text',
'label' => esc_html__( 'Callback', 'learndash' ),
'help_text' => esc_html__( 'Custom callback function to be used instead of default output', 'learndash' ),
'value' => '',
),
);
$this->shortcodes_option_fields = apply_filters( 'learndash_settings_fields', $this->shortcodes_option_fields, $this->shortcodes_section_key );
parent::init_shortcodes_section_fields();
}
}
}
shortcodes-sections/ld_course_expire_status.php 0000666 00000007746 15214240575 0016244 0 ustar 00 fields_args = $fields_args;
$this->shortcodes_section_key = 'ld_course_expire_status';
// translators: placeholder: Course.
$this->shortcodes_section_title = sprintf( esc_html_x( '%s Expire Status', 'placeholder: Course', 'learndash' ), LearnDash_Custom_Label::get_label( 'course' ) );
$this->shortcodes_section_type = 1;
// translators: placeholders: course.
$this->shortcodes_section_description = sprintf( esc_html_x( 'This shortcode displays the user %s access expire date.', 'placeholders: course', 'learndash' ), learndash_get_custom_label_lower( 'course' ) );
parent::__construct();
}
public function init_shortcodes_section_fields() {
$this->shortcodes_option_fields = array(
'course_id' => array(
'id' => $this->shortcodes_section_key . '_course_id',
'name' => 'course_id',
'type' => 'number',
// translators: placeholder: Course
'label' => sprintf( esc_html_x( '%s ID', 'placeholder: Course', 'learndash' ), LearnDash_Custom_Label::get_label( 'course' ) ),
// translators: placeholders: Course, Course.
'help_text' => sprintf( esc_html_x( 'Enter single %1$s ID. Leave blank for current %2$s.', 'placeholders: Course, Course', 'learndash' ), LearnDash_Custom_Label::get_label( 'course' ), LearnDash_Custom_Label::get_label( 'course' ) ),
'value' => '',
'class' => 'small-text',
),
'user_id' => array(
'id' => $this->shortcodes_section_key . '_user_id',
'name' => 'user_id',
'type' => 'number',
'label' => esc_html__( 'User ID', 'learndash' ),
'help_text' => esc_html__( 'Enter specific User ID. Leave blank for current User.', 'learndash' ),
'value' => '',
'class' => 'small-text',
),
'label_before' => array(
'id' => $this->shortcodes_section_key . '_label_before',
'name' => 'label_before',
'type' => 'text',
'label' => esc_html__( 'Label before', 'learndash' ),
'help_text' => esc_html__( 'The label prefix shown before the access expires', 'learndash' ),
'value' => '',
),
'label_after' => array(
'id' => $this->shortcodes_section_key . '_label_after',
'name' => 'label_after',
'type' => 'text',
'label' => esc_html__( 'Label after', 'learndash' ),
'help_text' => esc_html__( 'The label prefix shown after access has expired', 'learndash' ),
'value' => '',
),
'autop' => array(
'id' => $this->shortcodes_section_key . 'autop',
'name' => 'autop',
'type' => 'select',
'label' => esc_html__( 'Auto Paragraph', 'learndash' ),
'help_text' => esc_html__( 'Format shortcode content into proper pararaphs.', 'learndash' ),
'value' => 'true',
'options' => array(
'' => esc_html__( 'Yes (default)', 'learndash' ),
'false' => esc_html__( 'No', 'learndash' ),
),
),
);
if ( ( ! isset( $this->fields_args['post_type'] ) ) || ( ( 'sfwd-courses' !== $this->fields_args['post_type'] ) && ( 'sfwd-lessons' !== $this->fields_args['post_type'] ) && ( 'sfwd-topic' !== $this->fields_args['post_type'] ) ) ) {
$this->shortcodes_option_fields['course_id']['required'] = 'required';
// translators: placeholders: Course.
$this->shortcodes_option_fields['course_id']['help_text'] = sprintf( esc_html_x( 'Enter single %s ID.', 'placeholders: Course', 'learndash' ), LearnDash_Custom_Label::get_label( 'course' ) );
}
$this->shortcodes_option_fields = apply_filters( 'learndash_settings_fields', $this->shortcodes_option_fields, $this->shortcodes_section_key );
parent::init_shortcodes_section_fields();
}
}
}
shortcodes-sections/ld_group.php 0000666 00000005475 15214240575 0013116 0 ustar 00 fields_args = $fields_args;
$this->shortcodes_section_key = 'ld_group';
$this->shortcodes_section_title = esc_html__( 'Group', 'learndash' );
$this->shortcodes_section_type = 2;
$this->shortcodes_section_description = esc_html__( 'This shortcode shows the content if the user is enrolled in a specific group.', 'learndash' );
parent::__construct();
}
function init_shortcodes_section_fields() {
$this->shortcodes_option_fields = array(
'message' => array(
'id' => $this->shortcodes_section_key . '_message',
'name' => 'message',
'type' => 'textarea',
'label' => esc_html__( 'Message shown to user', 'learndash' ),
'help_text' => esc_html__( 'Message shown to user', 'learndash' ),
'value' => '',
'required' => 'required',
),
'group_id' => array(
'id' => $this->shortcodes_section_key . '_group_id',
'name' => 'group_id',
'type' => 'number',
'label' => esc_html__( 'Group ID', 'learndash' ),
'help_text' => esc_html__( 'Enter single Group ID. Leave blank for any Group.', 'learndash' ),
'value' => '',
'class' => 'small-text',
),
'user_id' => array(
'id' => $this->shortcodes_section_key . '_user_id',
'name' => 'user_id',
'type' => 'number',
'label' => esc_html__( 'User ID', 'learndash' ),
'help_text' => esc_html__( 'Enter specific User ID. Leave blank for current User.', 'learndash' ),
'value' => '',
'class' => 'small-text',
),
'autop' => array(
'id' => $this->shortcodes_section_key . 'autop',
'name' => 'autop',
'type' => 'select',
'label' => esc_html__( 'Auto Paragraph', 'learndash' ),
'help_text' => esc_html__( 'Format shortcode content into proper pararaphs.', 'learndash' ),
'value' => 'true',
'options' => array(
'' => esc_html__( 'Yes (default)', 'learndash' ),
'false' => esc_html__( 'No', 'learndash' ),
),
),
);
if ( ( ! isset( $this->fields_args['post_type'] ) ) || ( 'groups' != $this->fields_args['post_type'] ) ) {
$this->shortcodes_option_fields['group_id']['required'] = 'required';
$this->shortcodes_option_fields['group_id']['help_text'] = esc_html__( 'Enter single Group ID.', 'learndash' );
}
$this->shortcodes_option_fields = apply_filters( 'learndash_settings_fields', $this->shortcodes_option_fields, $this->shortcodes_section_key );
parent::init_shortcodes_section_fields();
}
}
}
shortcodes-sections/ld_lesson_list.php 0000666 00000030121 15214240575 0014302 0 ustar 00 fields_args = $fields_args;
$this->shortcodes_section_key = 'ld_lesson_list';
$this->shortcodes_section_title = sprintf( esc_html_x( '%s List', 'placeholder: Lesson', 'learndash' ), LearnDash_Custom_Label::get_label( 'lesson' ) );
$this->shortcodes_section_type = 1;
$this->shortcodes_section_description = sprintf( wp_kses_post( _x( "This shortcode shows list of %s. You can use this shortcode on any page if you don't want to use the default /%s/ page.", 'placeholders: lessons, lessons (URL slug)', 'learndash' ) ), learndash_get_custom_label_lower( 'lessons' ), LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Section_Permalinks', 'lessons' ) );
parent::__construct();
}
function init_shortcodes_section_fields() {
$this->shortcodes_option_fields = array(
'course_id' => array(
'id' => $this->shortcodes_section_key . '_course_id',
'name' => 'course_id',
'type' => 'number',
'label' => sprintf( esc_html_x( '%s ID', 'placeholder: Course', 'learndash' ), LearnDash_Custom_Label::get_label( 'course' ) ),
'help_text' => sprintf( esc_html_x( 'Enter single %1$s ID. Leave blank for all %2$s.', 'placeholders: Course, Courses', 'learndash' ), LearnDash_Custom_Label::get_label( 'course' ), LearnDash_Custom_Label::get_label( 'courses' ) ),
'value' => '',
'class' => 'small-text'
),
'orderby' => array(
'id' => $this->shortcodes_section_key . '_orderby',
'name' => 'orderby',
'type' => 'select',
'label' => esc_html__( 'Order by', 'learndash' ),
'help_text' => wp_kses_post( __( 'See the full list of available orderby options here.', 'learndash' ) ),
'value' => 'ID',
'options' => array(
'' => sprintf( esc_html_x('Order by %s. (default)', 'placeholder: course', 'learndash'), learndash_get_custom_label_lower( 'course' ) ),
'id' => esc_html__('ID - Order by post id.', 'learndash'),
'title' => esc_html__('Title - Order by post title', 'learndash'),
'date' => esc_html__('Date - Order by post date', 'learndash'),
'menu_order' => esc_html__('Menu - Order by Page Order Value', 'learndash'),
)
),
'order' => array(
'id' => $this->shortcodes_section_key . '_order',
'name' => 'order',
'type' => 'select',
'label' => esc_html__( 'Order', 'learndash' ),
'help_text' => esc_html__( 'Order', 'learndash' ),
'value' => 'ID',
'options' => array(
'' => sprintf( esc_html_x('Order per %s (default)', 'placeholder: course', 'learndash'), learndash_get_custom_label_lower( 'course' ) ),
'DESC' => esc_html__('DESC - highest to lowest values', 'learndash'),
'ASC' => esc_html__('ASC - lowest to highest values', 'learndash'),
)
),
'num' => array(
'id' => $this->shortcodes_section_key . '_num',
'name' => 'num',
'type' => 'number',
'label' => sprintf( esc_html_x( '%s Per Page', 'placeholders: lessons', 'learndash' ), LearnDash_Custom_Label::get_label( 'lessons' ) ),
'help_text' => sprintf( esc_html_x( '%1$s per page. Default is %2$d. Set to zero for all.', 'placeholders: lessons, default per page', 'learndash' ), LearnDash_Custom_Label::get_label( 'lessons' ), LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Section_General_Per_Page', 'per_page' ) ),
'value' => '',
'class' => 'small-text',
'attrs' => array(
'min' => 0,
'step' => 1
)
),
'show_content' => array(
'id' => $this->shortcodes_section_key . 'show_content',
'name' => 'show_content',
'type' => 'select',
'label' => sprintf( esc_html_x( 'Show %s Content', 'placeholder: Lesson', 'learndash'), LearnDash_Custom_Label::get_label( 'lesson' ) ),
'help_text' => sprintf( esc_html_x( 'show %s content.', 'placeholders: lesson', 'learndash' ), learndash_get_custom_label_lower( 'lesson' ) ),
'value' => 'true',
'options' => array(
'' => esc_html__( 'Yes (default)', 'learndash' ),
'false' => esc_html__('No', 'learndash'),
)
),
'show_thumbnail' => array(
'id' => $this->shortcodes_section_key . 'show_thumbnail',
'name' => 'show_thumbnail',
'type' => 'select',
'label' => sprintf( esc_html_x( 'Show %s Thumbnail', 'placeholder: Lesson', 'learndash'), LearnDash_Custom_Label::get_label( 'lesson' ) ),
'help_text' => sprintf( esc_html_x( 'shows a %s thumbnail.', 'placeholders: lesson', 'learndash' ), learndash_get_custom_label_lower( 'lesson' ) ),
'value' => 'true',
'options' => array(
'' => esc_html__( 'Yes (default)', 'learndash' ),
'false' => esc_html__( 'No', 'learndash' ),
)
),
);
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Courses_Builder', 'shared_steps' ) != 'yes' ) {
foreach( $this->shortcodes_option_fields['orderby']['options'] as $option_key => $option_label ) {
if ( empty( $option_key ) ) {
unset( $this->shortcodes_option_fields['orderby']['options'][$option_key] );
}
}
foreach( $this->shortcodes_option_fields['order']['options'] as $option_key => $option_label ) {
if ( empty( $option_key ) ) {
unset( $this->shortcodes_option_fields['order']['options'][$option_key] );
}
}
}
if ( defined( 'LEARNDASH_COURSE_GRID_FILE' ) ) {
$this->shortcodes_option_fields['col'] = array(
'id' => $this->shortcodes_section_key . '_col',
'name' => 'col',
'type' => 'number',
'label' => esc_html__('Columns','learndash'),
'help_text' => sprintf( esc_html_x( 'number of columns to show when using %s grid addon', 'placeholders: course', 'learndash' ), learndash_get_custom_label_lower( 'course' ) ),
'value' => '',
'class' => 'small-text'
);
}
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Lessons_Taxonomies', 'ld_lesson_category' ) == 'yes') {
$this->shortcodes_option_fields['lesson_cat'] = array(
'id' => $this->shortcodes_section_key . '_lesson_cat',
'name' => 'lesson_cat',
'type' => 'number',
'label' => sprintf( esc_html_x('%s Category ID', 'placeholder: Lesson', 'learndash'), LearnDash_Custom_Label::get_label( 'lesson' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned category id.', 'placeholders: lessons', 'learndash' ), learndash_get_custom_label_lower( 'lessons' ) ),
'value' => '',
'class' => 'small-text'
);
$this->shortcodes_option_fields['lesson_category_name'] = array(
'id' => $this->shortcodes_section_key . '_lesson_category_name',
'name' => 'lesson_category_name',
'type' => 'text',
'label' => sprintf( esc_html_x('%s Category Slug', 'placeholder: Lesson', 'learndash'), LearnDash_Custom_Label::get_label( 'lesson' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned category slug.', 'placeholders: lessons', 'learndash' ), learndash_get_custom_label_lower( 'lessons' ) ),
'value' => '',
);
$this->shortcodes_option_fields['lesson_categoryselector'] = array(
'id' => $this->shortcodes_section_key . '_lesson_categoryselector',
'name' => 'lesson_categoryselector',
'type' => 'checkbox',
'label' => sprintf( esc_html_x('%s Category Selector', 'placeholder: Lesson', 'learndash'), LearnDash_Custom_Label::get_label( 'lesson' ) ),
'help_text' => sprintf( esc_html_x( 'shows a %s category dropdown.', 'placeholders: lesson', 'learndash' ), learndash_get_custom_label_lower( 'lesson' ) ),
'value' => '',
'options' => array(
'true' => esc_html__('Yes', 'learndash'),
)
);
}
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Lessons_Taxonomies', 'ld_lesson_tag' ) == 'yes') {
$this->shortcodes_option_fields['lesson_tag_id'] = array(
'id' => $this->shortcodes_section_key . '_lesson_tag_id',
'name' => 'lesson_tag_id',
'type' => 'number',
'label' => sprintf( esc_html_x('%s Tag ID', 'placeholder: Lesson', 'learndash'), LearnDash_Custom_Label::get_label( 'Lesson' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned tag id.', 'placeholders: lessons', 'learndash' ), learndash_get_custom_label_lower( 'lessons' ) ),
'value' => '',
'class' => 'small-text'
);
$this->shortcodes_option_fields['lesson_tag'] = array(
'id' => $this->shortcodes_section_key . '_lesson_tag',
'name' => 'lesson_tag',
'type' => 'text',
'label' => sprintf( esc_html_x( '%s Tag Slug', 'placeholder: Lesson', 'learndash'), LearnDash_Custom_Label::get_label( 'lesson' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned tag slug.', 'placeholders: lessons', 'learndash' ), learndash_get_custom_label_lower( 'lessons' ) ),
'value' => '',
);
}
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Lessons_Taxonomies', 'wp_post_category' ) == 'yes') {
$this->shortcodes_option_fields['cat'] = array(
'id' => $this->shortcodes_section_key . '_cat',
'name' => 'cat',
'type' => 'number',
'label' => esc_html__('WP Category ID', 'learndash'),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned WP category id.', 'placeholders: lessons', 'learndash' ), learndash_get_custom_label_lower( 'lessons' ) ),
'value' => '',
'class' => 'small-text'
);
$this->shortcodes_option_fields['category_name'] = array(
'id' => $this->shortcodes_section_key . '_category_name',
'name' => 'category_name',
'type' => 'text',
'label' => esc_html__('WP Category Slug', 'learndash'),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned WP category slug.', 'placeholders: lessons', 'learndash' ), learndash_get_custom_label_lower( 'lessons' ) ),
'value' => '',
);
$this->shortcodes_option_fields['categoryselector'] = array(
'id' => $this->shortcodes_section_key . '_categoryselector',
'name' => 'categoryselector',
'type' => 'checkbox',
'label' => esc_html__('WP Category Selector', 'learndash'),
'help_text' => esc_html__( 'shows a WP category dropdown.', 'learndash' ),
'value' => '',
'options' => array(
'true' => esc_html__('Yes', 'learndash'),
)
);
}
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Lessons_Taxonomies', 'wp_post_tag' ) == 'yes') {
$this->shortcodes_option_fields['tag'] = array(
'id' => $this->shortcodes_section_key . '_tag',
'name' => 'tag',
'type' => 'text',
'label' => esc_html__( 'WP Tag Slug', 'learndash'),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned WP tag slug.', 'placeholders: lessons', 'learndash' ), learndash_get_custom_label_lower( 'lessons' ) ),
'value' => '',
);
$this->shortcodes_option_fields['tag_id'] = array(
'id' => $this->shortcodes_section_key . '_tag_id',
'name' => 'tag_id',
'type' => 'number',
'label' => esc_html__('WP Tag ID', 'learndash'),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned WP tag id.', 'placeholders: lessons', 'learndash' ), learndash_get_custom_label_lower( 'lessons' ) ),
'value' => '',
'class' => 'small-text'
);
}
$this->shortcodes_option_fields = apply_filters( 'learndash_settings_fields', $this->shortcodes_option_fields, $this->shortcodes_section_key );
parent::init_shortcodes_section_fields();
}
}
}
shortcodes-sections/learndash_login.php 0000666 00000012776 15214240575 0014436 0 ustar 00 fields_args = $fields_args;
$this->shortcodes_section_key = 'learndash_login';
$this->shortcodes_section_title = esc_html__( 'LearnDash Login', 'learndash' );
$this->shortcodes_section_type = 1;
$this->shortcodes_section_description = esc_html__( 'This shortcode adds the login button on any page', 'learndash' );
parent::__construct();
}
function init_shortcodes_section_fields() {
$this->shortcodes_option_fields = array(
'login_description' => array(
'id' => $this->shortcodes_section_key . '_login_description',
'name' => 'login_description',
'type' => 'html',
'label' => '',
'label_none' => true,
'input_full' => true,
'value' => wpautop( esc_html__( 'Controls the Login functionality.', 'learndash' ) ),
),
'login_url' => array(
'id' => $this->shortcodes_section_key . '_login_url',
'name' => 'login_url',
'type' => 'text',
'label' => esc_html__( 'Login URL', 'learndash' ),
'value' => '',
'help_text' => esc_html__( 'Override default login URL', 'learndash' ),
),
'login_label' => array(
'id' => $this->shortcodes_section_key . '_login_label',
'name' => 'login_label',
'type' => 'text',
'label' => esc_html__( 'Login Label', 'learndash' ),
'value' => '',
'help_text' => esc_html__( 'Override default label "Login"', 'learndash' ),
),
'login_placement' => array(
'id' => $this->shortcodes_section_key . '_login_placement',
'name' => 'login_placement',
'type' => 'select',
'label' => esc_html__( 'Login Icon Placement', 'learndash' ),
'help_text' => esc_html__( 'Login Icon Placement', 'learndash' ),
'value' => '',
'options' => array(
'' => esc_html__( 'Left - To left of label', 'learndash' ),
'right' => esc_html__( 'Right - To right of label', 'learndash' ),
'none' => esc_html__( 'None - No icon', 'learndash' ),
),
),
'login_button' => array(
'id' => $this->shortcodes_section_key . '_login_button',
'name' => 'login_button',
'type' => 'select',
'label' => esc_html__( 'Login Displayed as', 'learndash' ),
'help_text' => esc_html__( 'Display as Button or link', 'learndash' ),
'value' => 'button',
'options' => array(
'' => esc_html__( 'Button', 'learndash' ),
'link' => esc_html__( 'Link', 'learndash' ),
),
),
/*
'login_url_redirect' => array(
'id' => $this->shortcodes_section_key . '_login_url_redirect',
'name' => 'login_url_redirect',
'type' => 'text',
'label' => esc_html__('Login URL Redirect', 'learndash'),
'value' => '',
'help_text' => esc_html__( 'URL to redirect to after login. Default is the current page URL.', 'learndash' ),
),
*/
'logout_description' => array(
'id' => $this->shortcodes_section_key . '_logout_description',
'name' => 'logout_description',
'type' => 'html',
'label' => '',
'label_none' => true,
'input_full' => true,
'value' => wpautop( esc_html__( 'Controls the Logout functionality.', 'learndash' ) ),
),
'logout_url' => array(
'id' => $this->shortcodes_section_key . '_logout_url',
'name' => 'logout_url',
'type' => 'text',
'label' => esc_html__( 'Logout URL Redirect', 'learndash' ),
'value' => '',
'help_text' => esc_html__( 'Override default logout URL.', 'learndash' ),
),
'logout_label' => array(
'id' => $this->shortcodes_section_key . '_logout_label',
'name' => 'logout_label',
'type' => 'text',
'label' => esc_html__( 'Logout Label', 'learndash' ),
'value' => '',
'help_text' => esc_html__( 'Override default label "Logout"', 'learndash' ),
),
'logout_placement' => array(
'id' => $this->shortcodes_section_key . '_logout_placement',
'name' => 'logout_placement',
'type' => 'select',
'label' => esc_html__( 'Logout Icon Placement', 'learndash' ),
'help_text' => esc_html__( 'Logout Icon Placement', 'learndash' ),
'value' => '',
'options' => array(
'left' => esc_html__( 'Left - To left of label', 'learndash' ),
'' => esc_html__( 'Right - To right of label', 'learndash' ),
'none' => esc_html__( 'None - No icon', 'learndash' ),
),
),
'logout_button' => array(
'id' => $this->shortcodes_section_key . '_logout_button',
'name' => 'logout_button',
'type' => 'select',
'label' => esc_html__( 'Logout Displayed as Button', 'learndash' ),
'help_text' => esc_html__( 'Display as Button or link', 'learndash' ),
'value' => 'button',
'options' => array(
'' => esc_html__( 'Button', 'learndash' ),
'link' => esc_html__( 'Link', 'learndash' ),
),
),
);
$this->shortcodes_option_fields = apply_filters( 'learndash_settings_fields', $this->shortcodes_option_fields, $this->shortcodes_section_key );
parent::init_shortcodes_section_fields();
}
}
}
shortcodes-sections/ld_course_resume.php 0000666 00000006602 15214240575 0014633 0 ustar 00 fields_args = $fields_args;
$this->shortcodes_section_key = 'ld_course_resume';
$this->shortcodes_section_title = sprintf(
// translators: placeholders: Course.
esc_html_x( '%s Resume', 'placeholders: Course', 'learndash' ),
LearnDash_Custom_Label::get_label( 'course' )
);
$this->shortcodes_section_type = 2;
$this->shortcodes_section_description = sprintf(
// translators: placeholders: Course.
esc_html_x( 'Return to %s link/button.', 'placeholders: Course', 'learndash' ),
LearnDash_Custom_Label::get_label( 'course' )
);
parent::__construct();
}
function init_shortcodes_section_fields() {
$this->shortcodes_option_fields = array(
'course_id' => array(
'id' => $this->shortcodes_section_key . '_course_id',
'name' => 'course_id',
'type' => 'number',
'label' => sprintf(
// translators: placeholder: Course.
esc_html_x( '%s ID', 'placeholder: Course', 'learndash' ),
LearnDash_Custom_Label::get_label( 'course' )
),
'help_text' => sprintf(
// translators: placeholders: Course, Course.
esc_html_x( 'Enter single %1$s ID. Leave blank for current %2$s.', 'placeholders: Course, Course', 'learndash' ),
LearnDash_Custom_Label::get_label( 'course' ),
LearnDash_Custom_Label::get_label( 'course' )
),
'value' => '',
// 'required' => 'required',
'class' => 'small-text',
),
'user_id' => array(
'id' => $this->shortcodes_section_key . '_user_id',
'name' => 'user_id',
'type' => 'number',
'label' => esc_html__( 'User ID', 'learndash' ),
'help_text' => esc_html__( 'Enter specific User ID. Leave blank for current User.', 'learndash' ),
'value' => '',
'class' => 'small-text',
),
'label' => array(
'id' => $this->shortcodes_section_key . '_label',
'name' => 'label',
'type' => 'text',
'label' => esc_html__( 'Label', 'learndash' ),
'help_text' => esc_html__( 'Label for link shown to user', 'learndash' ),
'value' => '',
),
'button' => array(
'id' => $this->shortcodes_section_key . '_button',
'name' => 'button',
'type' => 'select',
'label' => esc_html__( 'Show as button', 'learndash' ),
'help_text' => esc_html__( 'shows as button content.', 'learndash' ),
'value' => 'true',
'options' => array(
'' => esc_html__( 'Yes (default)', 'learndash' ),
'false' => esc_html__( 'No', 'learndash' ),
),
),
'html_class' => array(
'id' => $this->shortcodes_section_key . '_html_class',
'name' => 'html_class',
'type' => 'text',
'label' => esc_html__( 'HTML Class', 'learndash' ),
'help_text' => esc_html__( 'HTML class for link element', 'learndash' ),
'value' => '',
),
);
$this->shortcodes_option_fields = apply_filters( 'learndash_settings_fields', $this->shortcodes_option_fields, $this->shortcodes_section_key );
parent::init_shortcodes_section_fields();
}
}
}
shortcodes-sections/ld_quiz_list.php 0000666 00000032411 15214240575 0013773 0 ustar 00 fields_args = $fields_args;
$this->shortcodes_section_key = 'ld_quiz_list';
$this->shortcodes_section_title = sprintf(
// translators: placeholder: Quiz.
esc_html_x( '%s List', 'placeholder: Quiz', 'learndash' ),
LearnDash_Custom_Label::get_label( 'quiz' )
);
$this->shortcodes_section_type = 1;
$this->shortcodes_section_description = sprintf(
wp_kses_post(
// translators: placeholders: quizzes, quizzes (URL slug).
_x( 'This shortcode shows list of %1$s. You can use this shortcode on any page if you don\'t want to use the default /%2$s/ page.', 'placeholders: quizzes, quizzes (URL slug)', 'learndash' )
),
learndash_get_custom_label_lower( 'quizzes' ), LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Section_Permalinks', 'quizzes' )
);
parent::__construct();
}
/**
* Initialize shortcode fields.
*
* @since 2.4.0
*/
public function init_shortcodes_section_fields() {
$this->shortcodes_option_fields = array(
'course_id' => array(
'id' => $this->shortcodes_section_key . '_course_id',
'name' => 'course_id',
'type' => 'number',
'label' => sprintf(
// translators: placeholder: Course.
esc_html_x( '%s ID', 'placeholder: Course', 'learndash' ),
LearnDash_Custom_Label::get_label( 'course' )
),
'help_text' => sprintf(
// translators: placeholders: Course, Courses.
esc_html_x( 'Enter single %1$s ID. Leave blank for all %2$s.', 'placeholders: Course, Courses', 'learndash' ),
LearnDash_Custom_Label::get_label( 'course' ), LearnDash_Custom_Label::get_label( 'courses' )
),
'value' => '',
'class' => 'small-text',
),
'lesson_id' => array(
'id' => $this->shortcodes_section_key . '_lesson_id',
'name' => 'lesson_id',
'type' => 'number',
'label' => sprintf( esc_html_x( '%s ID', 'placeholder: Lesson', 'learndash' ), LearnDash_Custom_Label::get_label( 'lesson' ) ),
'help_text' => sprintf( esc_html_x( 'Must be used with course_id. Enter single %1$s or %2$s ID. Leave blank for all step within %3$s. Set zero for global.', 'placeholders: Lesson, Topic, Course', 'learndash' ), LearnDash_Custom_Label::get_label( 'lesson' ), LearnDash_Custom_Label::get_label( 'topic' ), LearnDash_Custom_Label::get_label( 'lesson' ) ),
'value' => '',
'class' => 'small-text'
),
'orderby' => array(
'id' => $this->shortcodes_section_key . '_orderby',
'name' => 'orderby',
'type' => 'select',
'label' => esc_html__( 'Order by', 'learndash' ),
'help_text' => wp_kses_post( __( 'See the full list of available orderby options here.', 'learndash' ) ),
'value' => 'ID',
'options' => array(
'' => sprintf( esc_html_x('Order by %s. (default)', 'placeholder: course', 'learndash'), learndash_get_custom_label_lower( 'course' ) ),
'id' => esc_html__('ID - Order by post id.', 'learndash'),
'title' => esc_html__('Title - Order by post title', 'learndash'),
'date' => esc_html__('Date - Order by post date', 'learndash'),
'menu_order' => esc_html__('Menu - Order by Page Order Value', 'learndash'),
)
),
'order' => array(
'id' => $this->shortcodes_section_key . '_order',
'name' => 'order',
'type' => 'select',
'label' => esc_html__( 'Order', 'learndash' ),
'help_text' => esc_html__( 'Order', 'learndash' ),
'value' => 'ID',
'options' => array(
'' => sprintf( esc_html_x('Order per %s (default)', 'placeholder: course', 'learndash'), learndash_get_custom_label_lower( 'course' ) ),
'DESC' => esc_html__('DESC - highest to lowest values', 'learndash'),
'ASC' => esc_html__('ASC - lowest to highest values', 'learndash'),
)
),
'num' => array(
'id' => $this->shortcodes_section_key . '_num',
'name' => 'num',
'type' => 'number',
'label' => sprintf( esc_html_x( '%s Per Page', 'placeholders: quizzes', 'learndash'), LearnDash_Custom_Label::get_label( 'quizzes' ) ),
'help_text' => sprintf( esc_html_x( '%s per page. Default is %d. Set to zero for all.', 'placeholders: quizzes, default per page', 'learndash' ), LearnDash_Custom_Label::get_label( 'quizzes' ), LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Section_General_Per_Page', 'per_page' ) ),
'value' => '',
'class' => 'small-text',
'attrs' => array(
'min' => 0,
'step' => 1
)
),
'show_content' => array(
'id' => $this->shortcodes_section_key . 'show_content',
'name' => 'show_content',
'type' => 'select',
'label' => sprintf( esc_html_x('Show %s Content', 'placeholder: Quiz', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s content.', 'placeholders: quiz', 'learndash' ), learndash_get_custom_label_lower( 'quiz' ) ),
'value' => 'true',
'options' => array(
'' => esc_html__('Yes (default)', 'learndash'),
'false' => esc_html__('No', 'learndash'),
)
),
'show_thumbnail' => array(
'id' => $this->shortcodes_section_key . 'show_thumbnail',
'name' => 'show_thumbnail',
'type' => 'select',
'label' => sprintf( esc_html_x('Show %s Thumbnail', 'placeholder: Quiz', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ) ),
'help_text' => sprintf( esc_html_x( 'shows a %s thumbnail.', 'placeholders: quiz', 'learndash' ), learndash_get_custom_label_lower( 'quiz' ) ),
'value' => 'true',
'options' => array(
'' => esc_html__('Yes (default)', 'learndash'),
'false' => esc_html__('No', 'learndash'),
)
)
);
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Courses_Builder', 'shared_steps' ) != 'yes' ) {
foreach( $this->shortcodes_option_fields['orderby']['options'] as $option_key => $option_label ) {
if ( empty( $option_key ) ) {
unset( $this->shortcodes_option_fields['orderby']['options'][$option_key] );
}
}
foreach( $this->shortcodes_option_fields['order']['options'] as $option_key => $option_label ) {
if ( empty( $option_key ) ) {
unset( $this->shortcodes_option_fields['order']['options'][$option_key] );
}
}
}
if ( defined( 'LEARNDASH_COURSE_GRID_FILE' ) ) {
$this->shortcodes_option_fields['col'] = array(
'id' => $this->shortcodes_section_key . '_col',
'name' => 'col',
'type' => 'number',
'label' => esc_html__('Columns','learndash'),
'help_text' => sprintf( esc_html_x( 'number of columns to show when using %s grid addon', 'placeholders: course', 'learndash' ), learndash_get_custom_label_lower( 'course' ) ),
'value' => '',
'class' => 'small-text'
);
}
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Quizzes_Taxonomies', 'ld_quiz_category' ) == 'yes') {
$this->shortcodes_option_fields['quiz_cat'] = array(
'id' => $this->shortcodes_section_key . '_quiz_cat',
'name' => 'quiz_cat',
'type' => 'number',
'label' => sprintf( esc_html_x( '%s Category ID', 'placeholder: Quiz', 'learndash' ), LearnDash_Custom_Label::get_label( 'quiz' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned category id.', 'placeholders: quizzes', 'learndash' ), learndash_get_custom_label_lower( 'quizzes' ) ),
'value' => '',
'class' => 'small-text'
);
$this->shortcodes_option_fields['quiz_category_name'] = array(
'id' => $this->shortcodes_section_key . '_quiz_category_name',
'name' => 'quiz_category_name',
'type' => 'text',
'label' => sprintf( esc_html_x('%s Category Slug', 'placeholder: Quiz', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned category slug.', 'placeholders: quizzes', 'learndash' ), learndash_get_custom_label_lower( 'quizzes' ) ),
'value' => '',
);
$this->shortcodes_option_fields['quiz_categoryselector'] = array(
'id' => $this->shortcodes_section_key . '_quiz_categoryselector',
'name' => 'quiz_categoryselector',
'type' => 'checkbox',
'label' => sprintf( esc_html_x('%s Category Selector', 'placeholder: Quiz', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ) ),
'help_text' => sprintf( esc_html_x( 'shows a %s category dropdown.', 'placeholders: quiz', 'learndash' ), learndash_get_custom_label_lower( 'quiz' ) ),
'value' => '',
'options' => array(
'true' => esc_html__('Yes', 'learndash'),
)
);
}
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Quizzes_Taxonomies', 'ld_quiz_tag' ) == 'yes') {
$this->shortcodes_option_fields['quiz_tag_id'] = array(
'id' => $this->shortcodes_section_key . '_quiz_tag_id',
'name' => 'quiz_tag_id',
'type' => 'number',
'label' => sprintf( esc_html_x('%s Tag ID', 'placeholder: Quizzes', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned tag id.', 'placeholders: quizzes', 'learndash' ), learndash_get_custom_label_lower( 'quizzes' ) ),
'value' => '',
'class' => 'small-text'
);
$this->shortcodes_option_fields['quiz_tag'] = array(
'id' => $this->shortcodes_section_key . '_quiz_tag',
'name' => 'quiz_tag',
'type' => 'text',
'label' => sprintf( esc_html_x( '%s Tag Slug', 'placeholder: Quiz', 'learndash'), LearnDash_Custom_Label::get_label( 'quiz' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned tag slug.', 'placeholders: quizzes', 'learndash' ), learndash_get_custom_label_lower( 'quizzes' ) ),
'value' => '',
);
}
if ( LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Quizzes_Taxonomies', 'wp_post_category' ) == 'yes' ) {
$this->shortcodes_option_fields['cat'] = array(
'id' => $this->shortcodes_section_key . '_cat',
'name' => 'cat',
'type' => 'number',
'label' => esc_html__('WP Category ID', 'learndash'),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned WP category id.', 'placeholders: quizzes', 'learndash' ), learndash_get_custom_label_lower( 'quizzes' ) ),
'value' => '',
'class' => 'small-text'
);
$this->shortcodes_option_fields['category_name'] = array(
'id' => $this->shortcodes_section_key . '_category_name',
'name' => 'category_name',
'type' => 'text',
'label' => esc_html__( 'WP Category Slug', 'learndash' ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned WP category slug.', 'placeholders: quizzes', 'learndash' ), learndash_get_custom_label_lower( 'quizzes' ) ),
'value' => '',
);
$this->shortcodes_option_fields['categoryselector'] = array(
'id' => $this->shortcodes_section_key . '_categoryselector',
'name' => 'categoryselector',
'type' => 'checkbox',
'label' => esc_html__( 'WP Category Selector', 'learndash' ),
'help_text' => esc_html__( 'shows a WP category dropdown.', 'learndash' ),
'value' => '',
'options' => array(
'true' => esc_html__('Yes', 'learndash'),
)
);
}
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Quizzes_Taxonomies', 'wp_post_tag' ) == 'yes') {
$this->shortcodes_option_fields['tag'] = array(
'id' => $this->shortcodes_section_key . '_tag',
'name' => 'tag',
'type' => 'text',
'label' => esc_html__( 'WP Tag Slug', 'learndash'),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned WP tag slug.', 'placeholders: quizzes', 'learndash' ), learndash_get_custom_label_lower( 'quizzes' ) ),
'value' => '',
);
$this->shortcodes_option_fields['tag_id'] = array(
'id' => $this->shortcodes_section_key . '_tag_id',
'name' => 'tag_id',
'type' => 'number',
'label' => esc_html__('WP Tag ID', 'learndash'),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned WP tag id.', 'placeholders: quizzes', 'learndash' ), learndash_get_custom_label_lower( 'quizzes' ) ),
'value' => '',
'class' => 'small-text'
);
}
$this->shortcodes_option_fields = apply_filters( 'learndash_settings_fields', $this->shortcodes_option_fields, $this->shortcodes_section_key );
parent::init_shortcodes_section_fields();
}
}
}
shortcodes-sections/ld_video.php 0000666 00000003454 15214240575 0013063 0 ustar 00 fields_args = $fields_args;
$this->shortcodes_section_key = 'ld_video';
$this->shortcodes_section_type = 1;
// translators: placeholders: Lessons, Topics
$this->shortcodes_section_description = sprintf( esc_html_x( 'This shortcode is used on %1$s and %2$s where Video Progression is enabled. The video player will be added above the content. This shortcode allows positioning the player elsewhere within the content. This shortcode does not take any parameters.', 'placeholders: Lessons, Topics', 'learndash' ), LearnDash_Custom_Label::get_label( 'lessons' ), LearnDash_Custom_Label::get_label( 'topics' ) );
if ( learndash_get_post_type_slug( 'lesson' ) == $this->fields_args['post_type'] ) {
// translators: placeholder: lesson
$this->shortcodes_section_title = sprintf( esc_html_x( '%s Video', 'placeholder: lesson', 'learndash' ), LearnDash_Custom_Label::get_label( 'lesson' ) );
} elseif ( learndash_get_post_type_slug( 'topic' ) == $this->fields_args['post_type'] ) {
// translators: placeholder: topic
$this->shortcodes_section_title = sprintf( esc_html_x( '%s Video', 'placeholder: topic', 'learndash' ), LearnDash_Custom_Label::get_label( 'topic' ) );
}
parent::__construct();
}
public function init_shortcodes_section_fields() {
$this->shortcodes_option_fields = array();
$this->shortcodes_option_fields = apply_filters( 'learndash_settings_fields', $this->shortcodes_option_fields, $this->shortcodes_section_key );
parent::init_shortcodes_section_fields();
}
}
}
shortcodes-sections/course_inprogress.php 0000666 00000007331 15214240575 0015047 0 ustar 00 fields_args = $fields_args;
$this->shortcodes_section_key = 'course_inprogress';
// translators: placeholder: Course.
$this->shortcodes_section_title = sprintf( esc_html_x( '%s In Progress', 'placeholder: Course', 'learndash' ), LearnDash_Custom_Label::get_label( 'course' ) );
$this->shortcodes_section_type = 2;
// translators: placeholders: course.
$this->shortcodes_section_description = sprintf( wp_kses_post( _x( 'This shortcode shows the content if the user has started but not completed the %s. The shortcode can be used on any page or widget area.', 'placeholders: course', 'learndash' ) ), learndash_get_custom_label_lower( 'course' ) );
parent::__construct();
}
public function init_shortcodes_section_fields() {
$this->shortcodes_option_fields = array(
'message' => array(
'id' => $this->shortcodes_section_key . '_message',
'name' => 'message',
'type' => 'textarea',
'label' => esc_html__( 'Message shown to user', 'learndash' ),
'help_text' => esc_html__( 'Message shown to user', 'learndash' ),
'value' => '',
'required' => 'required',
),
'course_id' => array(
'id' => $this->shortcodes_section_key . '_course_id',
'name' => 'course_id',
'type' => 'number',
// translators: placeholder: Course.
'label' => sprintf( esc_html_x( '%s ID', 'placeholder: Course', 'learndash' ), LearnDash_Custom_Label::get_label( 'course' ) ),
// translators: placeholders: Course, Course.
'help_text' => sprintf( esc_html_x( 'Enter single %1$s ID. Leave blank for current %2$s.', 'placeholders: Course, Course', 'learndash' ), LearnDash_Custom_Label::get_label( 'course' ), LearnDash_Custom_Label::get_label( 'course' ) ),
'value' => '',
'class' => 'small-text',
),
'user_id' => array(
'id' => $this->shortcodes_section_key . '_user_id',
'name' => 'user_id',
'type' => 'number',
'label' => esc_html__( 'User ID', 'learndash' ),
'help_text' => esc_html__( 'Enter specific User ID. Leave blank for current User.', 'learndash' ),
'value' => '',
'class' => 'small-text',
),
'autop' => array(
'id' => $this->shortcodes_section_key . 'autop',
'name' => 'autop',
'type' => 'select',
'label' => esc_html__( 'Auto Paragraph', 'learndash' ),
'help_text' => esc_html__( 'Format shortcode content into proper pararaphs.', 'learndash' ),
'value' => 'true',
'options' => array(
'' => esc_html__( 'Yes (default)', 'learndash' ),
'false' => esc_html__( 'No', 'learndash' ),
),
),
);
if ( ( ! isset( $this->fields_args['post_type'] ) ) || ( ( 'sfwd-courses' !== $this->fields_args['post_type'] ) && ( 'sfwd-lessons' !== $this->fields_args['post_type'] ) && ( 'sfwd-topic' !== $this->fields_args['post_type'] ) ) ) {
$this->shortcodes_option_fields['course_id']['required'] = 'required';
// translators: placeholders: Course.
$this->shortcodes_option_fields['course_id']['help_text'] = sprintf( esc_html_x( 'Enter single %s ID.', 'placeholders: Course', 'learndash' ), LearnDash_Custom_Label::get_label( 'course' ) );
}
$this->shortcodes_option_fields = apply_filters( 'learndash_settings_fields', $this->shortcodes_option_fields, $this->shortcodes_section_key );
parent::init_shortcodes_section_fields();
}
}
}
shortcodes-sections/ld_user_course_points.php 0000666 00000002767 15214240575 0015715 0 ustar 00 fields_args = $fields_args;
$this->shortcodes_section_key = 'ld_user_course_points';
$this->shortcodes_section_title = sprintf( esc_html_x( 'User %s Points', 'placeholder: Course', 'learndash' ), LearnDash_Custom_Label::get_label( 'course' ) );
$this->shortcodes_section_type = 1;
$this->shortcodes_section_description = sprintf( esc_html_x( 'This shortcode shows the earned %s points for the user.', 'placeholders: course, course', 'learndash' ), learndash_get_custom_label_lower( 'course' ) );
parent::__construct();
}
function init_shortcodes_section_fields() {
$this->shortcodes_option_fields = array(
'user_id' => array(
'id' => $this->shortcodes_section_key . '_user_id',
'name' => 'user_id',
'type' => 'number',
'label' => esc_html__( 'User ID', 'learndash' ),
'help_text' => esc_html__('Enter specific User ID. Leave blank for current User.', 'learndash' ),
'value' => '',
'class' => 'small-text'
),
);
$this->shortcodes_option_fields = apply_filters( 'learndash_settings_fields', $this->shortcodes_option_fields, $this->shortcodes_section_key );
parent::init_shortcodes_section_fields();
}
}
}
shortcodes-sections/usermeta.php 0000666 00000003661 15214240575 0013123 0 ustar 00 fields_args = $fields_args;
$this->shortcodes_section_key = 'usermeta';
$this->shortcodes_section_title = esc_html__( 'User meta', 'learndash' );
$this->shortcodes_section_type = 1;
$this->shortcodes_section_description = wp_kses_post( __('This shortcode takes a parameter named field, which is the name of the user meta data field to be displayed. See the full list of available fields here. Note for security reasons some fields are not allowed.', 'learndash' ) );
parent::__construct();
}
function init_shortcodes_section_fields() {
$this->shortcodes_option_fields = array(
'field' => array(
'id' => $this->shortcodes_section_key . '_field',
'name' => 'field',
'type' => 'select',
'label' => esc_html__( 'Field', 'learndash' ),
'help_text' => esc_html__( 'This parameter determines the information to be shown by the shortcode.', 'learndash' ),
'value' => 'ID',
'options' => learndash_get_usermeta_shortcode_available_fields()
),
'user_id' => array(
'id' => $this->shortcodes_section_key . '_user_id',
'name' => 'user_id',
'type' => 'number',
'label' => esc_html__( 'User ID', 'learndash' ),
'help_text' => esc_html__('Enter specific User ID. Leave blank for current User.', 'learndash' ),
'value' => '',
'class' => 'small-text'
),
);
$this->shortcodes_option_fields = apply_filters( 'learndash_settings_fields', $this->shortcodes_option_fields, $this->shortcodes_section_key );
parent::init_shortcodes_section_fields();
}
}
}
shortcodes-sections/quizinfo.php 0000666 00000014623 15214240575 0013142 0 ustar 00 fields_args = $fields_args;
$this->shortcodes_section_key = 'quizinfo';
$this->shortcodes_section_title = sprintf( esc_html_x( '%s Info', 'placeholder: Quiz', 'learndash' ), LearnDash_Custom_Label::get_label( 'quiz' ) );
$this->shortcodes_section_type = 1;
$this->shortcodes_section_description = sprintf( esc_html_x( 'This shortcode displays information regarding %s attempts on the certificate. This shortcode can use the following parameters:', 'placeholders: quiz', 'learndash' ), learndash_get_custom_label_lower( 'quiz' ) );
parent::__construct();
}
function init_shortcodes_section_fields() {
$this->shortcodes_option_fields = array(
'show' => array(
'id' => $this->shortcodes_section_key . '_show',
'name' => 'show',
'type' => 'select',
'label' => esc_html__( 'Show', 'learndash' ),
'help_text' => sprintf( wp_kses_post( _x( 'This parameter determines the information to be shown by the shortcode./%s/ page.", 'placeholders: topics, topics (URL slug)', 'learndash' ) ), learndash_get_custom_label_lower( 'topics' ), LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Section_Permalinks', 'topics' ) );
parent::__construct();
}
function init_shortcodes_section_fields() {
$this->shortcodes_option_fields = array(
'course_id' => array(
'id' => $this->shortcodes_section_key . '_course_id',
'name' => 'course_id',
'type' => 'number',
'label' => sprintf( esc_html_x( '%s ID', 'placeholder: Course', 'learndash' ), LearnDash_Custom_Label::get_label( 'course' ) ),
'help_text' => sprintf( esc_html_x( 'Enter single %1$s ID. Leave blank for all %2$s.', 'placeholders: Course, Courses', 'learndash' ), LearnDash_Custom_Label::get_label( 'course' ), LearnDash_Custom_Label::get_label( 'courses' ) ),
'value' => '',
'class' => 'small-text'
),
'lesson_id' => array(
'id' => $this->shortcodes_section_key . '_lesson_id',
'name' => 'lesson_id',
'type' => 'number',
'label' => sprintf( esc_html_x( '%s ID', 'placeholder: Lesson', 'learndash' ), LearnDash_Custom_Label::get_label( 'lesson' ) ),
'help_text' => sprintf( esc_html_x( 'Must be used with course_id. Enter single %1$s ID. Leave blank for all %2$s within %3$s.', 'placeholders: Lesson, Lessons, Course', 'learndash' ), LearnDash_Custom_Label::get_label( 'lesson' ), LearnDash_Custom_Label::get_label( 'lessons' ), LearnDash_Custom_Label::get_label( 'lesson' ) ),
'value' => '',
'class' => 'small-text'
),
'orderby' => array(
'id' => $this->shortcodes_section_key . '_orderby',
'name' => 'orderby',
'type' => 'select',
'label' => esc_html__( 'Order by', 'learndash' ),
'help_text' => wp_kses_post( __( 'See the full list of available orderby options here.', 'learndash' ) ),
'value' => 'ID',
'options' => array(
'' => sprintf( esc_html_x('Order by %s. (default)', 'placeholder: course', 'learndash'), learndash_get_custom_label_lower( 'course' ) ),
'id' => esc_html__('ID - Order by post id.', 'learndash'),
'title' => esc_html__('Title - Order by post title', 'learndash'),
'date' => esc_html__('Date - Order by post date', 'learndash'),
'menu_order' => esc_html__('Menu - Order by Page Order Value', 'learndash'),
)
),
'order' => array(
'id' => $this->shortcodes_section_key . '_order',
'name' => 'order',
'type' => 'select',
'label' => esc_html__( 'Order', 'learndash' ),
'help_text' => esc_html__( 'Order', 'learndash' ),
'value' => 'ID',
'options' => array(
'' => sprintf( esc_html_x('Order per %s (default)', 'placeholder: course', 'learndash'), learndash_get_custom_label_lower( 'course' ) ),
'DESC' => esc_html__('DESC - highest to lowest values', 'learndash'),
'ASC' => esc_html__('ASC - lowest to highest values', 'learndash'),
)
),
'num' => array(
'id' => $this->shortcodes_section_key . '_num',
'name' => 'num',
'type' => 'number',
'label' => sprintf( esc_html_x( '%s Per Page', 'placeholders: topics', 'learndash' ), LearnDash_Custom_Label::get_label( 'topics' ) ),
'help_text' => sprintf( esc_html_x( '%s per page. Default is %d. Set to zero for all.', 'placeholders: topics, default per page', 'learndash' ), LearnDash_Custom_Label::get_label( 'topics' ), LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Section_General_Per_Page', 'per_page' ) ),
'value' => '',
'class' => 'small-text',
'attrs' => array(
'min' => 0,
'step' => 1
)
),
'show_content' => array(
'id' => $this->shortcodes_section_key . 'show_content',
'name' => 'show_content',
'type' => 'select',
'label' => sprintf( esc_html_x('Show %s Content', 'placeholder: Topic', 'learndash'), LearnDash_Custom_Label::get_label( 'topic' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s content.', 'placeholders: topic', 'learndash' ), learndash_get_custom_label_lower( 'topic' ) ),
'value' => 'true',
'options' => array(
'' => esc_html__('Yes (default)', 'learndash'),
'false' => esc_html__('No', 'learndash'),
)
),
'show_thumbnail' => array(
'id' => $this->shortcodes_section_key . 'show_thumbnail',
'name' => 'show_thumbnail',
'type' => 'select',
'label' => sprintf( esc_html_x('Show %s Thumbnail', 'placeholder: Topic', 'learndash'), LearnDash_Custom_Label::get_label( 'topic' ) ),
'help_text' => sprintf( esc_html_x( 'shows a %s thumbnail.', 'placeholders: topic', 'learndash' ), learndash_get_custom_label_lower( 'topic' ) ),
'value' => 'true',
'options' => array(
'' => esc_html__('Yes (default)', 'learndash'),
'false' => esc_html__('No', 'learndash'),
)
),
);
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Courses_Builder', 'shared_steps' ) != 'yes' ) {
foreach( $this->shortcodes_option_fields['orderby']['options'] as $option_key => $option_label ) {
if ( empty( $option_key ) ) {
unset( $this->shortcodes_option_fields['orderby']['options'][$option_key] );
}
}
foreach( $this->shortcodes_option_fields['order']['options'] as $option_key => $option_label ) {
if ( empty( $option_key ) ) {
unset( $this->shortcodes_option_fields['order']['options'][$option_key] );
}
}
}
if ( defined( 'LEARNDASH_COURSE_GRID_FILE' ) ) {
$this->shortcodes_option_fields['col'] = array(
'id' => $this->shortcodes_section_key . '_col',
'name' => 'col',
'type' => 'number',
'label' => esc_html__('Columns','learndash'),
'help_text' => sprintf( esc_html_x( 'number of columns to show when using %s grid addon', 'placeholders: course', 'learndash' ), learndash_get_custom_label_lower( 'course' ) ),
'value' => '',
'class' => 'small-text'
);
}
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Topics_Taxonomies', 'ld_topic_category' ) == 'yes') {
$this->shortcodes_option_fields['topic_cat'] = array(
'id' => $this->shortcodes_section_key . '_topic_cat',
'name' => 'topic_cat',
'type' => 'number',
'label' => sprintf( esc_html_x('%s Category ID', 'placeholder: Topics', 'learndash'), LearnDash_Custom_Label::get_label( 'topic' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned category id.', 'placeholders: topics', 'learndash' ), learndash_get_custom_label_lower( 'topics' ) ),
'value' => '',
'class' => 'small-text'
);
$this->shortcodes_option_fields['topic_category_name'] = array(
'id' => $this->shortcodes_section_key . '_topic_category_name',
'name' => 'topic_category_name',
'type' => 'text',
'label' => sprintf( esc_html_x('%s Category Slug', 'placeholder: Topic', 'learndash'), LearnDash_Custom_Label::get_label( 'topic' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned category slug.', 'placeholders: topics', 'learndash' ), learndash_get_custom_label_lower( 'topics' ) ),
'value' => '',
);
$this->shortcodes_option_fields['topic_categoryselector'] = array(
'id' => $this->shortcodes_section_key . '_topic_categoryselector',
'name' => 'topic_categoryselector',
'type' => 'checkbox',
'label' => sprintf( esc_html_x('%s Category Selector', 'placeholder: Topic', 'learndash'), LearnDash_Custom_Label::get_label( 'topic' ) ),
'help_text' => sprintf( esc_html_x( 'shows a %s category dropdown.', 'placeholders: topic', 'learndash' ), learndash_get_custom_label_lower( 'topic' ) ),
'value' => '',
'options' => array(
'true' => esc_html__('Yes', 'learndash'),
)
);
}
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Topics_Taxonomies', 'ld_topic_tag' ) == 'yes') {
$this->shortcodes_option_fields['topic_tag_id'] = array(
'id' => $this->shortcodes_section_key . '_topic_tag_id',
'name' => 'topic_tag_id',
'type' => 'number',
'label' => sprintf( esc_html_x('%s Tag ID', 'placeholder: Topic', 'learndash'), LearnDash_Custom_Label::get_label( 'topic' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned tag id.', 'placeholders: topics', 'learndash' ), learndash_get_custom_label_lower( 'topics' ) ),
'value' => '',
'class' => 'small-text'
);
$this->shortcodes_option_fields['topic_tag'] = array(
'id' => $this->shortcodes_section_key . '_topic_tag',
'name' => 'topic_tag',
'type' => 'text',
'label' => sprintf( esc_html_x( '%s Tag Slug', 'placeholder: Topic', 'learndash'), LearnDash_Custom_Label::get_label( 'topic' ) ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned tag slug.', 'placeholders: topics', 'learndash' ), learndash_get_custom_label_lower( 'topics' ) ),
'value' => '',
);
}
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Topics_Taxonomies', 'wp_post_category' ) == 'yes') {
$this->shortcodes_option_fields['cat'] = array(
'id' => $this->shortcodes_section_key . '_cat',
'name' => 'cat',
'type' => 'number',
'label' => esc_html__('WP Category ID', 'learndash'),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned WP category id.', 'placeholders: topics', 'learndash' ), learndash_get_custom_label_lower( 'topics' ) ),
'value' => '',
'class' => 'small-text'
);
$this->shortcodes_option_fields['category_name'] = array(
'id' => $this->shortcodes_section_key . '_category_name',
'name' => 'category_name',
'type' => 'text',
'label' => esc_html__( 'WP Category Slug', 'learndash' ),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned WP category slug.', 'placeholders: topics', 'learndash' ), learndash_get_custom_label_lower( 'topics' ) ),
'value' => '',
);
$this->shortcodes_option_fields['categoryselector'] = array(
'id' => $this->shortcodes_section_key . '_categoryselector',
'name' => 'categoryselector',
'type' => 'checkbox',
'label' => esc_html__( 'WP Category Selector', 'learndash' ),
'help_text' => esc_html__( 'shows a WP category dropdown.', 'learndash' ),
'value' => '',
'options' => array(
'true' => esc_html__('Yes', 'learndash'),
)
);
}
if ( LearnDash_Settings_Section::get_section_setting('LearnDash_Settings_Topics_Taxonomies', 'wp_post_tag' ) == 'yes') {
$this->shortcodes_option_fields['tag'] = array(
'id' => $this->shortcodes_section_key . '_tag',
'name' => 'tag',
'type' => 'text',
'label' => esc_html__( 'WP Tag Slug', 'learndash'),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned WP tag slug.', 'placeholders: topics', 'learndash' ), learndash_get_custom_label_lower( 'topics' ) ),
'value' => '',
);
$this->shortcodes_option_fields['tag_id'] = array(
'id' => $this->shortcodes_section_key . '_tag_id',
'name' => 'tag_id',
'type' => 'number',
'label' => esc_html__('WP Tag ID', 'learndash'),
'help_text' => sprintf( esc_html_x( 'shows %s with mentioned WP tag id.', 'placeholders: topics', 'learndash' ), learndash_get_custom_label_lower( 'topics' ) ),
'value' => '',
'class' => 'small-text'
);
}
$this->shortcodes_option_fields = apply_filters( 'learndash_settings_fields', $this->shortcodes_option_fields, $this->shortcodes_section_key );
parent::init_shortcodes_section_fields();
}
}
}
settings-sections/class-ld-settings-section-courses-cpt.php 0000666 00000020713 15214240575 0020225 0 ustar 00 settings_screen_id = 'sfwd-courses_page_courses-options';
// The page ID (different than the screen ID).
$this->settings_page_id = 'courses-options';
// This is the 'option_name' key used in the wp_options table.
$this->setting_option_key = 'learndash_settings_courses_cpt';
// This is the HTML form field prefix used.
$this->setting_field_prefix = 'learndash_settings_courses_cpt';
// Used within the Settings API to uniquely identify this section.
$this->settings_section_key = 'cpt_options';
// Section label/header.
$this->settings_section_label = sprintf(
// translators: placeholder: Course.
esc_html_x( '%s Custom Post Type Options', 'Course Custom Post Type Options', 'learndash' ),
learndash_get_custom_label( 'course' )
);
// Used to show the section description above the fields. Can be empty.
$this->settings_section_description = sprintf(
// translators: placeholder: Course.
esc_html_x( 'Control the LearnDash %s Custom Post Type Options.', 'placeholder: Course', 'learndash' ),
learndash_get_custom_label( 'course' )
);
parent::__construct();
}
/**
* Initialize the metabox settings values.
*/
public function load_settings_values() {
parent::load_settings_values();
if ( ( false === $this->setting_option_values ) || ( '' === $this->setting_option_values ) ) {
if ( '' === $this->setting_option_values ) {
$this->setting_option_values = array();
}
$this->setting_option_values = array(
'include_in_search' => 'yes',
'has_archive' => 'yes',
'has_feed' => '',
'supports' => array( 'thumbnail', 'revisions' ),
);
}
if ( ! isset( $this->setting_option_values['include_in_search'] ) ) {
if ( ( isset( $this->setting_option_values['exclude_from_search'] ) ) && ( 'yes' === $this->setting_option_values['exclude_from_search'] ) ) {
$this->setting_option_values['include_in_search'] = '';
} else {
$this->setting_option_values['include_in_search'] = 'yes';
}
}
if ( ! isset( $this->setting_option_values['has_archive'] ) ) {
$this->setting_option_values['has_archive'] = 'yes';
}
if ( ! isset( $this->setting_option_values['has_feed'] ) ) {
$this->setting_option_values['has_feed'] = '';
}
if ( ! isset( $this->setting_option_values['supports'] ) ) {
$this->setting_option_values['supports'] = array( 'thumbnail','revisions' );
}
}
/**
* Initialize the metabox settings fields.
*/
public function load_settings_fields() {
$cpt_archive_url = home_url( LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Section_Permalinks', 'courses' ) );
$cpt_rss_url = add_query_arg( 'post_type', 'sfwd-courses', get_post_type_archive_feed_link( 'post' ) );
$this->setting_option_fields = array(
'include_in_search' => array(
'name' => 'include_in_search',
'type' => 'checkbox-switch',
'label' => sprintf(
// translators: placeholder: Course.
esc_html_x( '%s Search', 'placeholder: Course', 'learndash' ),
learndash_get_custom_label( 'course' )
),
'help_text' => sprintf(
// translators: placeholder: course.
esc_html_x( 'Includes the %s post type in front end search results', 'placeholder: course', 'learndash' ),
learndash_get_custom_label_lower( 'course' )
),
'value' => $this->setting_option_values['include_in_search'],
'options' => array(
'yes' => '',
),
),
'has_archive' => array(
'name' => 'has_archive',
'type' => 'checkbox-switch',
'label' => esc_html__( 'Archive Page', 'learndash' ),
'help_text' => sprintf(
// translators: placeholders: courses, link to WP Permalins page.
esc_html_x( 'Enables the front end archive page where all %1$s are listed. You must %2$s for the change to take effect.', 'placeholders: courses, link to WP Permalins page', 'learndash' ),
learndash_get_custom_label_lower( 'courses' ),
'' . esc_html__( 're-save your permalinks', 'learndash' ) . ''
),
'value' => $this->setting_option_values['has_archive'],
'options' => array(
'' => '',
'yes' => sprintf(
// translators: placeholder: URL for CPT Archive.
esc_html_x( 'Archive URL: %s', 'placeholder: URL for CPT Archive', 'learndash' ),
'' . $cpt_archive_url . ''
),
),
'child_section_state' => ( 'yes' === $this->setting_option_values['has_archive'] ) ? 'open' : 'closed',
),
'has_feed' => array(
'name' => 'has_feed',
'type' => 'checkbox-switch',
'label' => esc_html__( 'RSS/Atom Feed', 'learndash' ),
'help_text' => sprintf(
// translators: placeholder: course
esc_html_x( 'Enables an RSS feed for all %1$s posts.', 'placeholder: course', 'learndash' ),
learndash_get_custom_label_lower( 'course' )
),
'value' => $this->setting_option_values['has_feed'],
'options' => array(
'' => '',
'yes' => sprintf(
// translators: placeholder: URL for CPT Archive.
esc_html_x( 'RSS Feed URL: %s', 'placeholder: URL for RSS Feed', 'learndash' ),
'' . $cpt_rss_url . ''
),
),
'parent_setting' => 'has_archive',
),
'supports' => array(
'name' => 'supports',
'type' => 'checkbox',
'label' => esc_html__( 'Editor Supported Settings', 'learndash' ),
'help_text' => esc_html__( 'Enables WordPress supported settings within the editor and theme.', 'learndash' ),
'value' => $this->setting_option_values['supports'],
'options' => array(
'thumbnail' => esc_html__( 'Featured image', 'learndash' ),
'comments' => esc_html__( 'Comments', 'learndash' ),
'custom-fields' => esc_html__( 'Custom Fields', 'learndash' ),
'revisions' => esc_html__( 'Revisions', 'learndash' ),
),
),
);
$this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_section_key );
parent::load_settings_fields();
}
/**
* Intercept the WP options save logic and check that we have a valid nonce.
*
* @since 3.0
* @param array $value Array of section fields values.
* @param array $old_value Array of old values.
* @param string $section_key Section option key should match $this->setting_option_key.
*/
public function section_pre_update_option( $new_values = '', $old_values = '', $setting_option_key = '' ) {
if ( $setting_option_key === $this->setting_option_key ) {
$new_values = parent::section_pre_update_option( $new_values, $old_values, $setting_option_key );
if ( ! isset( $new_values['include_in_search'] ) ) {
$new_values['include_in_search'] = '';
}
if ( ! isset( $new_values['has_archive'] ) ) {
$new_values['has_archive'] = '';
$new_values['has_feed'] = '';
}
if ( ! isset( $new_values['has_feed'] ) ) {
$new_values['has_feed'] = '';
}
if ( ! isset( $new_values['supports'] ) ) {
$new_values['supports'] = array();
}
if ( $new_values !== $old_values ) {
if ( ( ! isset( $old_values['has_archive'] ) ) || ( $new_values['has_archive'] !== $old_values['has_archive'] ) ) {
learndash_setup_rewrite_flush();
}
//if ( in_array( 'comments', $new_values['supports'] ) ) {
// learndash_update_posts_comment_status( 'sfwd-courses', 'open' );
//} else {
// learndash_update_posts_comment_status( 'sfwd-courses', 'closed' );
//}
}
}
return $new_values;
}
// End of functions.
}
}
add_action(
'learndash_settings_sections_init',
function() {
LearnDash_Settings_Courses_CPT::add_section_instance();
}
);
settings-sections/class-ld-settings-section-general-rest-api.php 0000666 00000015546 15214240575 0021125 0 ustar 00 settings_page_id = 'learndash_lms_settings';
// This is the 'option_name' key used in the wp_options table.
$this->setting_option_key = 'learndash_settings_rest_api';
// This is the HTML form field prefix used.
$this->setting_field_prefix = 'learndash_settings_rest_api';
// Used within the Settings API to uniquely identify this section.
$this->settings_section_key = 'settings_rest_api';
// Section label/header.
$this->settings_section_label = esc_html__( 'REST API Settings', 'learndash' );
$this->settings_section_description = esc_html__( 'Control and customize the REST API endpoints.', 'learndash' );
parent::__construct();
}
/**
* Initialize the metabox settings values.
*/
public function load_settings_values() {
parent::load_settings_values();
if ( ! isset( $this->setting_option_values['enabled'] ) ) {
$this->setting_option_values['enabled'] = 'yes';
}
if ( ( ! isset( $this->setting_option_values['sfwd-courses'] ) ) || ( empty( $this->setting_option_values['sfwd-courses'] ) ) ) {
$this->setting_option_values['sfwd-courses'] = 'sfwd-courses';
}
if ( ( ! isset( $this->setting_option_values['sfwd-lessons'] ) ) || ( empty( $this->setting_option_values['sfwd-lessons'] ) ) ) {
$this->setting_option_values['sfwd-lessons'] = 'sfwd-lessons';
}
if ( ( ! isset( $this->setting_option_values['sfwd-topic'] ) ) || ( empty( $this->setting_option_values['sfwd-topic'] ) ) ) {
$this->setting_option_values['sfwd-topic'] = 'sfwd-topic';
}
if ( ( ! isset( $this->setting_option_values['sfwd-quiz'] ) ) || ( empty( $this->setting_option_values['sfwd-quiz'] ) ) ) {
$this->setting_option_values['sfwd-quiz'] = 'sfwd-quiz';
}
if ( ( ! isset( $this->setting_option_values['sfwd-question'] ) ) || ( empty( $this->setting_option_values['sfwd-question'] ) ) ) {
$this->setting_option_values['sfwd-question'] = 'sfwd-question';
}
if ( ( ! isset( $this->setting_option_values['users'] ) ) || ( empty( $this->setting_option_values['users'] ) ) ) {
$this->setting_option_values['users'] = 'users';
}
if ( ( ! isset( $this->setting_option_values['groups'] ) ) || ( empty( $this->setting_option_values['groups'] ) ) ) {
$this->setting_option_values['groups'] = 'groups';
}
}
/**
* Initialize the metabox settings fields.
*/
public function load_settings_fields() {
$this->setting_option_fields = array(
'enabled' => array(
'name' => 'enabled',
'type' => 'checkbox-switch',
'label' => esc_html__( 'Enabled REST API', 'learndash' ),
'help_text' => esc_html__( 'Customize the LearnDash REST API namespace and endpoints. Leave text fields blank to revert to default.', 'learndash' ),
'value' => 'yes',
'options' => array(
'yes' => array(
'label' => '',
'description' => '',
'tooltip' => esc_html__( 'REST API must be enabled', 'learndash' ),
),
),
'attrs' => array(
'disabled' => 'disabled',
),
'child_section_state' => ( 'yes' === $this->setting_option_values['enabled'] ) ? 'open' : 'closed',
),
'sfwd-courses' => array(
'name' => 'sfwd-courses',
'type' => 'text',
'label' => sprintf(
// translators: placeholder: Course.
_x( '%s Endpoint Slug', 'placeholder: Course', 'learndash' ),
LearnDash_Custom_Label::get_label( 'course' )
),
'value' => $this->setting_option_values['sfwd-courses'],
'class' => 'regular-text',
'parent_setting' => 'enabled',
),
'sfwd-lessons' => array(
'name' => 'sfwd-lessons',
'type' => 'text',
'label' => sprintf(
// translators: placeholder: Lesson.
_x( '%s Endpoint Slug', 'placeholder: Lesson', 'learndash' ),
LearnDash_Custom_Label::get_label( 'lesson' )
),
'value' => $this->setting_option_values['sfwd-lessons'],
'class' => 'regular-text',
'parent_setting' => 'enabled',
),
'sfwd-topic' => array(
'name' => 'sfwd-topic',
'type' => 'text',
'label' => sprintf(
// translators: placeholder: Topic.
_x( '%s Endpoint Slug', 'placeholder: Topic', 'learndash' ),
LearnDash_Custom_Label::get_label( 'topic' )
),
'value' => $this->setting_option_values['sfwd-topic'],
'class' => 'regular-text',
'parent_setting' => 'enabled',
),
'sfwd-quiz' => array(
'name' => 'sfwd-quiz',
'type' => 'text',
'label' => sprintf(
// translators: placeholder: Quiz.
_x( '%s Endpoint Slug', 'placeholder: Quiz', 'learndash' ),
LearnDash_Custom_Label::get_label( 'quiz' )
),
'value' => $this->setting_option_values['sfwd-quiz'],
'class' => 'regular-text',
'parent_setting' => 'enabled',
),
'sfwd-question' => array(
'name' => 'sfwd-question',
'type' => 'text',
'label' => sprintf(
// translators: placeholder: Question.
_x( '%s Endpoint Slug', 'placeholder: Question', 'learndash' ),
LearnDash_Custom_Label::get_label( 'question' )
),
'value' => $this->setting_option_values['sfwd-question'],
'class' => 'regular-text',
'parent_setting' => 'enabled',
),
'users' => array(
'name' => 'users',
'type' => 'text',
'label' => esc_html__( 'User Endpoint Slug', 'learndash' ),
'value' => $this->setting_option_values['users'],
'class' => 'regular-text',
'parent_setting' => 'enabled',
),
'groups' => array(
'name' => 'groups',
'type' => 'text',
'label' => esc_html__( 'Groups Endpoint Slug', 'learndash' ),
'value' => $this->setting_option_values['groups'],
'class' => 'regular-text',
'parent_setting' => 'enabled',
),
);
$this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_section_key );
parent::load_settings_fields();
}
}
}
add_action(
'learndash_settings_sections_init',
function() {
LearnDash_Settings_Section_General_REST_API::add_section_instance();
}
);
settings-sections/class-ld-settings-section-support-learndash.php 0000666 00000100650 15214240575 0021430 0 ustar 00 settings_page_id = 'learndash_support';
// This is the 'option_name' key used in the wp_options table.
$this->setting_option_key = 'ld_settings';
// This is the HTML form field prefix used.
//$this->setting_field_prefix = 'learndash_settings_paypal';
// Used within the Settings API to uniquely identify this section.
$this->settings_section_key = 'settings_support_ld_settings';
// Section label/header.
$this->settings_section_label = esc_html__( 'LearnDash Settings', 'learndash' );
add_filter( 'learndash_support_sections_init', array( $this, 'learndash_support_sections_init' ) );
add_action( 'learndash_section_fields_before', array( $this, 'show_support_section' ), 30, 2 );
parent::__construct();
}
public function learndash_support_sections_init( $support_sections = array() ) {
global $wpdb, $wp_version, $wp_rewrite;
global $sfwd_lms;
$ABSPATH_tmp = str_replace( '\\', '/', ABSPATH );
/************************************************************************************************
* LearnDash Settings
************************************************************************************************/
if ( ! isset( $support_sections[ $this->setting_option_key ] ) ) {
$this->settings_set = array();
$this->settings_set['header'] = array(
'html' => $this->settings_section_label,
'text' => $this->settings_section_label,
);
$this->settings_set['columns'] = array(
'label' => array(
'html' => esc_html__( 'Setting', 'learndash' ),
'text' => 'Setting',
'class' => 'learndash-support-settings-left',
),
'value' => array(
'html' => esc_html__( 'Value', 'learndash' ),
'text' => 'Value',
'class' => 'learndash-support-settings-right',
),
);
$this->settings_set['settings'] = array();
$LEARNDASH_VERSION_value = '';
$LEARNDASH_VERSION_value_html = '';
$ld_version_history = learndash_data_upgrades_setting( 'version_history' );
if ( ! empty( $ld_version_history ) ) {
krsort( $ld_version_history );
$ld_version_history = array_slice( $ld_version_history, 0, 5, true );
$_first_item = true;
foreach( $ld_version_history as $timestamp => $version ) {
$version_date = ' - ';
if ( ! empty( $timestamp ) ) {
$version_date = learndash_adjust_date_time_display( $timestamp );
}
if ( true === $_first_item ) {
$_first_item = false;
$ld_license_info = get_option( 'nss_plugin_info_sfwd_lms' );
if ( ( $ld_license_info ) && ( property_exists( $ld_license_info, 'new_version' ) ) && ( ! empty( $ld_license_info->new_version ) ) ) {
if ( version_compare( $version, $ld_license_info->new_version, 'ne' ) ) {
$LEARNDASH_VERSION_value_html = '' . $version . ' ' . ': ' . $version_date . ' - ' .
sprintf(
// translators: placeholder: version number.
esc_html_x( 'Installed version does not match latest (%s).', 'placeholder: version number', 'learndash' ),
$ld_license_info->new_version
) . ' ' . esc_html__( 'Please upgrade.', 'learndash' ) . '' . "settings_page_id = 'learndash_lms_settings'; // This is the 'option_name' key used in the wp_options table. $this->setting_option_key = 'learndash_settings_courses_themes'; // This is the HTML form field prefix used. $this->setting_field_prefix = 'learndash_settings_courses_themes'; // Used within the Settings API to uniquely identify this section. $this->settings_section_key = 'themes'; // Section label/header. $this->settings_section_label = esc_html__( 'Design & Content Elements', 'learndash' ); // Used to show the section description above the fields. Can be empty $this->settings_section_description = esc_html__( 'Alter the look and feel of your Learning Management System', 'learndash' ); add_action( 'learndash_section_fields_after', array( $this, 'learndash_section_fields_after' ), 10, 2 ); parent::__construct(); } /** * Initialize the metabox settings values. */ public function load_settings_values() { parent::load_settings_values(); $themes = LearnDash_Theme_Register::get_themes(); $this->themes_list = array(); foreach ( $themes as $theme ) { $this->themes_list[ $theme['theme_key'] ] = $theme['theme_name']; } if ( ( ! isset( $this->setting_option_values['active_theme'] ) ) || ( empty( $this->setting_option_values['active_theme'] ) ) ) { $ld_prior_version = learndash_data_upgrades_setting( 'prior_version' ); if ( 'new' === $ld_prior_version ) { $this->setting_option_values['active_theme'] = LEARNDASH_DEFAULT_THEME; } else { $this->setting_option_values['active_theme'] = LEARNDASH_LEGACY_THEME; } } } /** * Initialize the metabox settings fields. */ public function load_settings_fields() { $this->setting_option_fields = array( 'active_theme' => array( 'name' => 'active_theme', 'type' => 'select', 'label' => esc_html__( 'Active Template', 'learndash' ), 'help_text' => esc_html__( 'New front-end design options and settings can be used when the LearnDash 3.0 template is activated.', 'learndash' ), 'value' => $this->setting_option_values['active_theme'], 'options' => $this->themes_list, ), ); $this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_section_key ); parent::load_settings_fields(); } public function learndash_section_fields_after( $settings_section_key = '', $settings_screen_id ) { if ( $settings_section_key === $this->settings_section_key ) { $themes = LearnDash_Theme_Register::get_themes(); if ( ! empty( $themes ) ) { global $wp_settings_sections; global $wp_settings_fields; $active_theme_key = LearnDash_Theme_Register::get_active_theme_key(); foreach ( $themes as $theme ) { $theme_instance = LearnDash_Theme_Register::get_theme_instance( $theme['theme_key'] ); $theme_settings_sections = $theme_instance->get_theme_settings_sections(); if ( ! empty( $theme_settings_sections ) ) { foreach ( $theme_settings_sections as $section_key => $section_instance ) { if ( isset( $wp_settings_fields[ $section_instance->settings_page_id ][ $section_key ] ) ) { $theme_state = 'closed'; if ( $active_theme_key === $theme_instance->get_theme_key() ) { $theme_state = 'open'; } echo '
' . get_option( 'date_format' ) . '',
'' . get_option( 'time_format' ) . ''
);
$this->setting_option_fields = array_merge(
$this->setting_option_fields,
array(
'quiz_builder_time_formats' => array(
'name' => 'quiz_builder_time_formats',
'type' => 'checkbox-switch',
'label' => sprintf(
// translators: placeholder: Quiz.
esc_html_x( 'Custom %s Time Formats', 'placeholder: Quiz', 'learndash' ),
learndash_get_custom_label( 'quiz' )
),
'help_text' => sprintf(
// translators: placeholder: Quiz, Quiz.
esc_html_x( 'Customize the default time format for the %1$s Leaderboard and %2$s Statistics. ', 'placeholder: Quiz, Quiz', 'learndash' ),
learndash_get_custom_label( 'Quiz' ),
learndash_get_custom_label( 'Quiz' )
),
'value' => $this->setting_option_values['quiz_builder_time_formats'],
'options' => array(
'' => $time_formats_off_state_text,
'yes' => '',
),
'child_section_state' => ( 'yes' === $this->setting_option_values['quiz_builder_time_formats'] ) ? 'open' : 'closed',
),
)
);
$wp_date_format = get_option( 'date_format' );
$wp_time_format = get_option( 'time_format' );
$wp_date_time_format = $wp_date_format . ' ' . $wp_time_format;
$date_time_formats = array_unique(
apply_filters(
'learndash_quiz_date_time_formats',
array(
$wp_date_time_format,
'd.m.Y H:i',
'Y/m/d g:i A',
'Y/m/d \a\t g:i A',
'Y/m/d \a\t g:ia',
__( 'M j, Y @ G:i' ),
)
)
);
if ( ! empty( $date_time_formats ) ) {
$options = array(
$wp_date_time_format => '' . date_i18n( $wp_date_time_format ) . '' . $wp_date_format . ' ' . $wp_time_format . ' - ' . __( 'WordPress default', 'learndash' ),
);
foreach ( $date_time_formats as $format ) {
if ( ! isset( $options[ $format ] ) ) {
$options[ $format ] = '' . date_i18n( $format ) . '' . $format . '';
}
}
}
$options['custom'] = '' . esc_html__( 'Custom', 'learndash' ) . '';
if ( ! in_array( $this->setting_option_values['statistics_time_format'], $date_time_formats ) ) {
$this->setting_option_values['statistics_time_format'] = 'custom';
}
$this->setting_option_fields['statistics_time_format'] = array(
'name' => 'statistics_time_format',
'type' => 'radio',
'label' => esc_html__( 'Statistic time format ', 'learndash' ),
'help_text' => esc_html__( 'Statistic time format ', 'learndash' ),
'default' => $wp_date_time_format,
'value' => $this->setting_option_values['statistics_time_format'],
'options' => $options,
'parent_setting' => 'quiz_builder_time_formats',
);
$options['custom'] = '' . esc_html__( 'Custom', 'learndash' ) . '';
if ( ! in_array( $this->setting_option_values['toplist_time_format'], $date_time_formats ) ) {
$this->setting_option_values['toplist_time_format'] = 'custom';
}
$this->setting_option_fields['toplist_time_format'] = array(
'name' => 'toplist_time_format',
'type' => 'radio',
'label' => esc_html__( 'Leaderboard time format', 'learndash' ),
'help_text' => esc_html__( 'Leaderboard time format', 'learndash' ),
'default' => $wp_date_time_format,
'value' => $this->setting_option_values['toplist_time_format'],
'options' => $options,
'parent_setting' => 'quiz_builder_time_formats',
);
$template_mapper = new WpProQuiz_Model_TemplateMapper();
$quiz_templates = $template_mapper->fetchAll( WpProQuiz_Model_Template::TEMPLATE_TYPE_QUIZ, false );
if ( ( ! empty( $quiz_templates ) ) && ( is_array( $quiz_templates ) ) ) {
foreach ( $quiz_templates as $template_quiz ) {
$template_name = $template_quiz->getName();
$template_id = $template_quiz->getTemplateId();
if ( ( ! empty( $template_name ) ) && ( ! isset( $this->setting_option_values['quiz_templates'][ $template_id ] ) ) ) {
$this->setting_option_values['quiz_templates'][ $template_id ] = esc_html( $template_name );
}
}
sort( $this->setting_option_values['quiz_templates'] );
}
$this->setting_option_fields['quiz_template'] = array(
'name' => 'quiz_template',
'type' => 'select-edit-delete',
'label' => sprintf(
// translators: placeholder: Quiz.
esc_html_x( '%s Template Management', 'placeholder: Quiz', 'learndash' ),
LearnDash_Custom_Label::get_label( 'quiz' )
),
'help_text' => esc_html__( 'Select a template to update or delete the title.', 'learndash' ),
'value' => '',
'placeholder' => esc_html__( 'Select a template', 'learndash' ),
'options' => $this->setting_option_values['quiz_templates'],
'buttons' => array(
'delete' => esc_html__( 'Delete', 'learndash' ),
'update' => esc_html__( 'Update', 'learndash' ),
),
);
$this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_section_key );
parent::load_settings_fields();
}
/**
* Intercept the WP options save logic and check that we have a valid nonce.
*
* @since 3.0
* @param array $value Array of section fields values.
* @param array $old_value Array of old values.
* @param string $section_key Section option key should match $this->setting_option_key.
*/
public function section_pre_update_option( $current_values = '', $old_values = '', $option = '' ) {
if ( $option === $this->setting_option_key ) {
$current_values = parent::section_pre_update_option( $current_values, $old_values, $option );
if ( $current_values !== $old_values ) {
//if ( ( isset( $current_values['force_quiz_builder'] ) ) && ( 'yes' === $current_values['force_quiz_builder'] ) ) {
// $current_values['quiz_builder_enabled'] = 'yes';
//}
//if ( ( isset( $current_values['force_shared_questions'] ) ) && ( 'yes' === $current_values['force_shared_questions'] ) ) {
// $current_values['quiz_builder_shared_questions'] = 'yes';
//}
//if ( ( isset( $current_values['shared_questions'] ) ) && ( 'yes' === $current_values['shared_questions'] ) ) {
// if ( ( ! isset( $current_values['quiz_builder_enabled'] ) ) || ( 'yes' !== $current_values['quiz_builder_enabled'] ) ) {
// $current_values['quiz_builder_shared_questions'] = 'no';
// }
//}
if ( ( isset( $current_values['quiz_builder_enabled'] ) ) && ( 'yes' === $current_values['quiz_builder_enabled'] ) ) {
$current_values['quiz_builder_per_page'] = absint( $current_values['quiz_builder_per_page'] );
} else {
$current_values['quiz_builder_shared_questions'] = '';
$current_values['quiz_builder_per_page'] = LEARNDASH_LMS_DEFAULT_WIDGET_PER_PAGE;
}
$wp_date_format = get_option( 'date_format' );
$wp_time_format = get_option( 'time_format' );
$wp_date_time_format = $wp_date_format . ' ' . $wp_time_format;
if ( ( isset( $current_values['quiz_builder_time_formats'] ) ) && ( 'yes' === $current_values['quiz_builder_time_formats'] ) ) {
if ( ( isset( $current_values['statistics_time_format'] ) ) && ( 'custom' === $current_values['statistics_time_format'] ) ) {
if ( ( isset( $_POST['statistics_time_format_custom'] ) ) && ( ! empty( $_POST['statistics_time_format_custom'] ) ) ) {
$current_values['statistics_time_format'] = esc_attr( $_POST['statistics_time_format_custom'] );
} else {
$current_values['statistics_time_format'] = '';
}
}
if ( $wp_date_time_format === $current_values['statistics_time_format'] ) {
$current_values['statistics_time_format'] = '';
}
if ( ( isset( $current_values['toplist_time_format'] ) ) && ( 'custom' === $current_values['toplist_time_format'] ) ) {
if ( ( isset( $_POST['toplist_date_format_custom'] ) ) && ( ! empty( $_POST['toplist_date_format_custom'] ) ) ) {
$current_values['toplist_time_format'] = esc_attr( $_POST['toplist_date_format_custom'] );
} else {
$current_values['toplist_time_format'] = '';
}
}
if ( $wp_date_time_format === $current_values['toplist_time_format'] ) {
$current_values['toplist_time_format'] = '';
}
} else {
$current_values['statistics_time_format'] = '';
$current_values['toplist_time_format'] = '';
}
}
}
return $current_values;
}
/**
* This function handles the AJAX actions from the browser.
*
* @since 2.5.9
*/
public function ajax_action() {
$reply_data = array( 'status' => false );
if ( current_user_can( 'wpProQuiz_edit_quiz' ) ) {
if ( ( isset( $_POST['field_nonce'] ) ) && ( ! empty( $_POST['field_nonce'] ) ) && ( isset( $_POST['field_key'] ) ) && ( ! empty( $_POST['field_key'] ) ) && ( wp_verify_nonce( esc_attr( $_POST['field_nonce'] ), $_POST['field_key'] ) ) ) {
if ( isset( $_POST['field_action'] ) ) {
if ( 'update' === $_POST['field_action'] ) {
if ( ( isset( $_POST['field_value'] ) ) && ( ! empty( $_POST['field_value'] ) ) && ( isset( $_POST['field_text'] ) ) && ( ! empty( $_POST['field_text'] ) ) ) {
$template_id = intval( $_POST['field_value'] );
$template_new_name = esc_attr( $_POST['field_text'] );
$template_mapper = new WpProQuiz_Model_TemplateMapper();
$template = $template_mapper->fetchById( $template_id );
if ( ( $template ) && ( is_a( $template, 'WpProQuiz_Model_Template' ) ) ) {
$template_current_name = $template->getName();
if ( $template_current_name !== $template_new_name ) {
$update_ret = $template_mapper->updateName( $template_id, $template_new_name );
if ( $update_ret ) {
$reply_data['status'] = true;
$reply_data['message'] = '' . __( 'Template updated.', 'learndash' ) . '';
}
}
}
}
} elseif ( 'delete' === $_POST['field_action'] ) {
if ( ( isset( $_POST['field_value'] ) ) && ( ! empty( $_POST['field_value'] ) ) ) {
$template_id = intval( $_POST['field_value'] );
$template_mapper = new WpProQuiz_Model_TemplateMapper();
$template = $template_mapper->fetchById( $template_id );
if ( ( $template ) && ( is_a( $template, 'WpProQuiz_Model_Template' ) ) ) {
$update_ret = $template_mapper->delete( $template_id );
if ( $update_ret ) {
$reply_data['status'] = true;
$reply_data['message'] = '' . __( 'Template deleted.', 'learndash' ) . '';
}
}
}
}
}
}
}
if ( ! empty( $reply_data ) ) {
echo wp_json_encode( $reply_data );
}
wp_die(); // This is required to terminate immediately and return a proper response.
}
// End of functions.
}
}
add_action(
'learndash_settings_sections_init',
function() {
LearnDash_Settings_Quizzes_Management_Display::add_section_instance();
}
);
settings-sections/class-ld-settings-section-support-database-tables.php 0000666 00000013041 15214240575 0022500 0 ustar 00 settings_page_id = 'learndash_support';
// This is the 'option_name' key used in the wp_options table.
$this->setting_option_key = 'ld_database_tables';
// This is the HTML form field prefix used.
//$this->setting_field_prefix = 'learndash_settings_paypal';
// Used within the Settings API to uniquely identify this section.
$this->settings_section_key = 'settings_support_ld_database_tables';
// Section label/header.
$this->settings_section_label = esc_html__( 'Database Tables', 'learndash' );
add_filter( 'learndash_support_sections_init', array( $this, 'learndash_support_sections_init' ) );
add_action( 'learndash_section_fields_before', array( $this, 'show_support_section' ), 30, 2 );
parent::__construct();
}
public function learndash_support_sections_init( $support_sections = array() ) {
global $wpdb, $wp_version, $wp_rewrite;
global $sfwd_lms;
$ABSPATH_tmp = str_replace( '\\', '/', ABSPATH );
/************************************************************************************************
* Learndash Database Tables
************************************************************************************************/
if ( ! isset( $support_sections[ $this->setting_option_key ] ) ) {
$this->settings_set = array();
$this->settings_set['header'] = array(
'html' => $this->settings_section_label,
'text' => $this->settings_section_label,
);
$this->settings_set['columns'] = array(
'label' => array(
'html' => esc_html__( 'Table Name', 'learndash' ),
'text' => 'Table Name',
'class' => 'learndash-support-settings-left',
),
'value' => array(
'html' => esc_html__( 'Present', 'learndash' ),
'text' => 'Present',
'class' => 'learndash-support-settings-right',
),
);
$this->settings_set['desc'] = '' . esc_html__( 'When the LearnDash plugin or related add-ons are activated they will create the following tables. If the tables are not present try reactivating the plugin. If the table still do not show check the DB_USER defined in your wp-config.php and ensure it has the proper permissions to create tables. Check with your host for help.', 'learndash' ) . '
'; $grants = learndash_get_db_user_grants(); if ( ! empty( $grants ) ) { if ( ( array_search( 'ALL PRIVILEGES', $grants ) === false ) && ( array_search( 'CREATE', $grants ) === false ) ) { $this->settings_set['desc'] .= '' . esc_html__( 'The DB_USER defined in your wp-config.php does not have CREATE permission.', 'learndash' ) . '
'; } } $this->settings_set['settings'] = array(); $this->db_tables = LDLMS_DB::get_tables(); $this->db_tables = apply_filters( 'learndash_support_db_tables', $this->db_tables ); if ( ! empty( $this->db_tables ) ) { sort( $this->db_tables ); $this->db_tables = array_unique( $this->db_tables ); foreach ( $this->db_tables as $db_table ) { $this->settings_set['settings'][ $db_table ] = array( 'label' => $db_table, ); if ( $wpdb->get_var( "SHOW TABLES LIKE '" . $db_table . "'" ) == $db_table ) { if ( true === apply_filters( 'learndash_support_db_tables_rows', true ) ) { $table_rows = $wpdb->get_var( "SELECT table_rows from information_schema.tables WHERE table_schema = '" . DB_NAME . "' AND table_name = '" . $db_table . "'" ); $rows_str = ' - rows(' . $table_rows . ')'; } else { $rows_str = ''; } $this->settings_set['settings'][ $db_table ]['value'] = 'Yes' . $rows_str; $this->settings_set['settings'][ $db_table ]['value_html'] = '' . esc_html__( 'Yes', 'learndash' ) . '' . $rows_str; } else { $this->settings_set['settings'][ $db_table ]['value'] = 'No' . ' - (X)'; $this->settings_set['settings'][ $db_table ]['value_html'] = '' . esc_html__( 'No', 'learndash' ) . ''; } } } $this->system_info['ld_database_tables'] = apply_filters( 'learndash_support_section', $this->settings_set, 'ld_database_tables' ); $support_sections[ $this->setting_option_key ] = apply_filters( 'learndash_support_section', $this->settings_set, $this->setting_option_key ); } return $support_sections; } public function show_support_section( $settings_section_key = '', $settings_screen_id = '' ) { if ( $settings_section_key === $this->settings_section_key ) { $support_page_instance = LearnDash_Settings_Page::get_page_instance( 'LearnDash_Settings_Page_Support' ); if ( $support_page_instance ) { $support_page_instance->show_support_section( $this->setting_option_key ); } } } // End of functions. } } add_action( 'learndash_settings_sections_init', function() { LearnDash_Settings_Section_Support_Database_Tables::add_section_instance(); } ); settings-sections/class-ld-settings-section-support-templates.php 0000666 00000026416 15214240575 0021474 0 ustar 00 settings_page_id = 'learndash_support'; // This is the 'option_name' key used in the wp_options table. $this->setting_option_key = 'ld_templates'; // This is the HTML form field prefix used. //$this->setting_field_prefix = 'learndash_settings_paypal'; // Used within the Settings API to uniquely identify this section. $this->settings_section_key = 'settings_support_ld_templates'; // Section label/header. $this->settings_section_label = esc_html__( 'Templates', 'learndash' ); add_filter( 'learndash_support_sections_init', array( $this, 'learndash_support_sections_init' ) ); add_action( 'learndash_section_fields_before', array( $this, 'show_support_section' ), 30, 2 ); parent::__construct(); } public function learndash_support_sections_init( $support_sections = array() ) { global $wpdb, $wp_version, $wp_rewrite; global $sfwd_lms; $ABSPATH_tmp = str_replace( '\\', '/', ABSPATH ); /************************************************************************************************ * Learndash Templates. ************************************************************************************************/ if ( ! isset( $support_sections[ $this->setting_option_key ] ) ) { $this->load_templates(); $this->settings_set = array(); $this->settings_set['header'] = array( 'html' => $this->settings_section_label, 'text' => $this->settings_section_label, ); $this->settings_set['columns'] = array( 'label' => array( 'html' => esc_html__( 'Template Name', 'learndash' ), 'text' => 'Template Name', 'class' => 'learndash-support-settings-left', ), 'value' => array( 'html' => esc_html__( 'Template Path', 'learndash' ), 'text' => 'Template Path', 'class' => 'learndash-support-settings-right', ), ); $this->settings_set['desc'] = ''; $this->settings_set['desc'] .= '' . esc_html__( 'Current Active LD Theme', 'learndash' ) . ': ' . LearnDash_Theme_Register::get_active_theme_name() . '
'; $template_paths = SFWD_LMS::get_template_paths( 'xxx.php' ); $theme_root = get_theme_root(); $theme_root = str_replace( '\\', '/', $theme_root ); $this->settings_set['desc'] .= '' . esc_html__( 'The following is the search order paths for override templates, relative to site root:', 'learndash' ); $this->settings_set['desc'] .= '
Warning: This will remove ALL LearnDash data including any custom database tables.', 'learndash' ); ?>
' . $cpt_archive_url . ''
),
),
'child_section_state' => ( 'yes' === $this->setting_option_values['has_archive'] ) ? 'open' : 'closed',
),
'has_feed' => array(
'name' => 'has_feed',
'type' => 'checkbox-switch',
'label' => esc_html__( 'RSS/Atom Feed', 'learndash' ),
'help_text' => sprintf(
// translators: placeholder: quiz
esc_html_x( 'Enables an RSS feed for all %1$s posts.', 'placeholder: quiz', 'learndash' ),
learndash_get_custom_label_lower( 'quiz' )
),
'value' => $this->setting_option_values['has_feed'],
'options' => array(
'' => '',
'yes' => sprintf(
// translators: placeholder: URL for CPT Archive.
esc_html_x( 'RSS Feed URL: %s', 'placeholder: URL for RSS Feed', 'learndash' ),
'' . $cpt_rss_url . ''
),
),
'parent_setting' => 'has_archive',
),
'supports' => array(
'name' => 'supports',
'type' => 'checkbox',
'label' => esc_html__( 'Editor Supported Settings', 'learndash' ),
'help_text' => esc_html__( 'Enables WordPress supported settings within the editor and theme.', 'learndash' ),
'value' => $this->setting_option_values['supports'],
'options' => array(
'thumbnail' => esc_html__( 'Featured image', 'learndash' ),
'comments' => esc_html__( 'Comments', 'learndash' ),
'custom-fields' => esc_html__( 'Custom Fields', 'learndash' ),
'revisions' => esc_html__( 'Revisions', 'learndash' ),
),
),
);
$this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_section_key );
parent::load_settings_fields();
}
/**
* Intercept the WP options save logic and check that we have a valid nonce.
*
* @since 3.0
* @param array $value Array of section fields values.
* @param array $old_value Array of old values.
* @param string $section_key Section option key should match $this->setting_option_key.
*/
public function section_pre_update_option( $new_values = '', $old_values = '', $setting_option_key = '' ) {
if ( $setting_option_key === $this->setting_option_key ) {
$new_values = parent::section_pre_update_option( $new_values, $old_values, $setting_option_key );
if ( ! isset( $new_values['include_in_search'] ) ) {
$new_values['include_in_search'] = '';
}
if ( ! isset( $new_values['has_archive'] ) ) {
$new_values['has_archive'] = '';
$new_values['has_feed'] = '';
}
if ( ! isset( $new_values['has_feed'] ) ) {
$new_values['has_feed'] = '';
}
if ( ! isset( $new_values['supports'] ) ) {
$new_values['supports'] = array();
}
if ( $new_values !== $old_values ) {
if ( ( ! isset( $old_values['has_archive'] ) ) || ( $new_values['has_archive'] !== $old_values['has_archive'] ) ) {
learndash_setup_rewrite_flush();
}
//if ( in_array( 'comments', $new_values['supports'] ) ) {
// learndash_update_posts_comment_status( 'sfwd-quiz', 'open' );
//} else {
// learndash_update_posts_comment_status( 'sfwd-quiz', 'closed' );
//}
}
}
return $new_values;
}
// End of functions.
}
}
add_action(
'learndash_settings_sections_init',
function() {
LearnDash_Settings_Quizzes_CPT::add_section_instance();
}
);
settings-sections/class-ld-settings-section-general-per-page.php 0000666 00000020272 15214240575 0021071 0 ustar 00 settings_page_id = 'learndash_lms_settings';
// This is the 'option_name' key used in the wp_options table.
$this->setting_option_key = 'learndash_settings_per_page';
// This is the HTML form field prefix used.
$this->setting_field_prefix = 'learndash_settings_per_page';
// Used within the Settings API to uniquely identify this section.
$this->settings_section_key = 'settings_per_page';
// Section label/header.
$this->settings_section_label = esc_html__( 'Global Pagination Settings', 'learndash' );
$this->settings_section_description = esc_html__( 'Specify the default number of items displayed per page for various listing outputs.', 'learndash' );
parent::__construct();
}
/**
* Initialize the metabox settings values.
*/
public function load_settings_values() {
parent::load_settings_values();
if ( ! isset( $this->setting_option_values['progress_num'] ) ) {
$this->setting_option_values['progress_num'] = LEARNDASH_LMS_DEFAULT_WIDGET_PER_PAGE;
}
if ( ! isset( $this->setting_option_values['quiz_num'] ) ) {
$this->setting_option_values['quiz_num'] = LEARNDASH_LMS_DEFAULT_WIDGET_PER_PAGE;
}
if ( ( LEARNDASH_LMS_DEFAULT_WIDGET_PER_PAGE === $this->setting_option_values['progress_num'] ) && ( LEARNDASH_LMS_DEFAULT_WIDGET_PER_PAGE === $this->setting_option_values['quiz_num'] ) ) {
$this->setting_option_values['profile_enabled'] = '';
} else {
$this->setting_option_values['profile_enabled'] = 'yes';
}
if ( ! isset( $this->setting_option_values['per_page'] ) ) {
$this->setting_option_values['per_page'] = LEARNDASH_LMS_DEFAULT_WIDGET_PER_PAGE;
}
if ( ! isset( $this->setting_option_values['question_num'] ) ) {
$this->setting_option_values['question_num'] = LEARNDASH_LMS_DEFAULT_WIDGET_PER_PAGE;
}
}
/**
* Validate settings field.
*
* @param string $val Value to be validated.
* @param string $key settings fields key.
* @param array $args Settings field args array.
*
* @return integer $val.
*/
public function validate_section_field_per_page( $val, $key, $args = array() ) {
// Get the digits only.
if ( ( isset( $args['field']['validate_args']['allow_empty'] ) ) && ( true === $args['field']['validate_args']['allow_empty'] ) ) {
$val = preg_replace( '/[^0-9]/', '', $val );
}
if ( '' === $val ) {
switch ( $key ) {
case 'per_page':
$val = LEARNDASH_LMS_DEFAULT_WIDGET_PER_PAGE;
break;
case 'progress_num':
$val = LEARNDASH_LMS_DEFAULT_WIDGET_PER_PAGE;
break;
case 'quiz_num':
$val = LEARNDASH_LMS_DEFAULT_WIDGET_PER_PAGE;
break;
case 'question_num':
$val = LEARNDASH_LMS_DEFAULT_WIDGET_PER_PAGE;
break;
}
}
// IF profile is NOT enabled we make sure to clear the quiz and progress values.
if ( ! isset( $args['post_fields']['profile_enabled'] ) ) {
if ( ( 'quiz_num' === $key ) || ( 'progress_num' === $key ) ) {
return LEARNDASH_LMS_DEFAULT_WIDGET_PER_PAGE;
}
}
return intval( $val );
}
/**
* Initialize the metabox settings fields.
*/
public function load_settings_fields() {
$this->setting_option_fields = array(
'profile_enabled' => array(
'name' => 'profile_enabled',
'type' => 'checkbox-switch',
'label' => esc_html__( 'WP Profile', 'learndash' ),
'help_text' => esc_html__( 'Controls the pagination for the WordPress Profile LearnDash elements.', 'learndash' ),
'value' => $this->setting_option_values['profile_enabled'],
'options' => array(
'yes' => '',
'' => sprintf(
// translators: placeholder: default per page number.
esc_html_x( 'Pagination defaults to %d', 'placeholder: default per page number', 'learndash' ),
LEARNDASH_LMS_DEFAULT_WIDGET_PER_PAGE
),
),
'child_section_state' => ( 'yes' === $this->setting_option_values['profile_enabled'] ) ? 'open' : 'closed',
),
'progress_num' => array(
'name' => 'progress_num',
'type' => 'number',
'label' => sprintf(
// translators: placeholder: Course.
esc_html_x( '%s Progress', 'placeholder: Course', 'learndash' ),
LearnDash_Custom_Label::get_label( 'course' )
),
'value' => $this->setting_option_values['progress_num'],
'attrs' => array(
'step' => 1,
'min' => 0,
),
'input_label' => sprintf(
// translators: placeholder: courses.
esc_html_x( '%s per page', 'placeholder: courses', 'learndash' ),
learndash_get_custom_label_lower( 'course' )
),
'validate_callback' => array( $this, 'validate_section_field_per_page' ),
'validate_args' => array(
'allow_empty' => 1,
),
'parent_setting' => 'profile_enabled',
),
'quiz_num' => array(
'name' => 'quiz_num',
'type' => 'number',
'label' => sprintf(
// translators: placeholders: Quiz.
esc_html_x( '%s Attempts', 'placeholder: Quiz', 'learndash' ),
LearnDash_Custom_Label::get_label( 'quiz' )
),
'value' => $this->setting_option_values['quiz_num'],
'attrs' => array(
'step' => 1,
'min' => 0,
),
'input_label' => sprintf(
// translators: placeholder: quizzes.
esc_html_x( '%s per page', 'placeholder: quizzes', 'learndash' ),
learndash_get_custom_label_lower( 'quizzes' )
),
'validate_callback' => array( $this, 'validate_section_field_per_page' ),
'validate_args' => array(
'allow_empty' => 1,
),
'parent_setting' => 'profile_enabled',
),
'per_page' => array(
'name' => 'per_page',
'type' => 'number',
'label' => esc_html__( 'Shortcodes & Widgets', 'learndash' ),
'help_text' => esc_html__( 'Controls the global pagination for the LD shortcodes as well as courseinfo widget. These can be overridden individually.', 'learndash' ),
'value' => $this->setting_option_values['per_page'],
'attrs' => array(
'step' => 1,
'min' => 0,
),
'validate_callback' => array( $this, 'validate_section_field_per_page' ),
'validate_args' => array(
'allow_empty' => 1,
),
),
'question_num' => array(
'name' => 'question_num',
'type' => 'number',
'label' => sprintf(
// translators: placeholders: Question.
esc_html_x( 'Backend %s Widget', 'placeholder: Question', 'learndash' ),
LearnDash_Custom_Label::get_label( 'question' )
),
'help_text' => sprintf(
// translators: placeholders: Questions, quiz, question.
esc_html_x( 'Controls the pagination for the %1$s admin widget when editing a %2$s or %3$s.', 'Questions, quiz, question', 'learndash' ),
learndash_get_custom_label( 'questions' ),
learndash_get_custom_label_lower( 'quiz' ),
learndash_get_custom_label_lower( 'question' )
),
'value' => $this->setting_option_values['question_num'],
'attrs' => array(
'step' => 1,
'min' => 0,
),
'validate_callback' => array( $this, 'validate_section_field_per_page' ),
'validate_args' => array(
'allow_empty' => 1,
),
),
);
$this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_section_key );
parent::load_settings_fields();
}
}
}
add_action(
'learndash_settings_sections_init',
function() {
LearnDash_Settings_Section_General_Per_Page::add_section_instance();
}
);
settings-sections/class-ld-settings-section-questions-taxonomies.php 0000666 00000025034 15214240575 0022175 0 ustar 00 settings_screen_id = 'sfwd-question_page_questions-options';
// The page ID (different than the screen ID).
$this->settings_page_id = 'questions-options';
// This is the 'option_name' key used in the wp_options table.
$this->setting_option_key = 'learndash_settings_questions_taxonomies';
// This is the HTML form field prefix used.
$this->setting_field_prefix = 'learndash_settings_questions_taxonomies';
// Used within the Settings API to uniquely identify this section.
$this->settings_section_key = 'taxonomies';
// Section label/header.
$this->settings_section_label = sprintf(
// translators: placeholder: Quiz.
esc_html_x( '%s Taxonomies', 'placeholder: Question', 'learndash' ),
LearnDash_Custom_Label::get_label( 'question' )
);
// Used to show the section description above the fields. Can be empty.
$this->settings_section_description = sprintf(
// translators: placeholder: Quiz, Questions.
esc_html_x( 'Control which taxonomies can be used with the LearnDash %1$s %2$s.', 'placeholder: Quiz, Questions', 'learndash' ),
learndash_get_custom_label( 'quiz' ),
learndash_get_custom_label_lower( 'questions' )
);
parent::__construct();
// Hook to handle the AJAX delete/update actions.
add_action( 'wp_ajax_' . $this->setting_field_prefix, array( $this, 'ajax_action' ) );
}
/**
* Initialize the metabox settings values.
*/
public function load_settings_values() {
parent::load_settings_values();
$_init = false;
if ( false === $this->setting_option_values ) {
$_init = true;
$this->setting_option_values = array(
'proquiz_question_category' => 'yes',
'ld_question_category' => 'no',
'ld_question_tag' => 'no',
'wp_post_category' => 'no',
'wp_post_tag' => 'no',
);
// If this is a new install we want to turn off WP Post Category/Tag.
$ld_prior_version = learndash_data_upgrades_setting( 'prior_version' );
if ( 'new' === $ld_prior_version ) {
$this->setting_option_values['wp_post_category'] = 'no';
$this->setting_option_values['wp_post_tag'] = 'no';
}
}
$this->setting_option_values = wp_parse_args(
$this->setting_option_values,
array(
'proquiz_question_category' => 'yes',
'ld_question_category' => 'no',
'ld_question_tag' => 'no',
'wp_post_category' => 'no',
'wp_post_tag' => 'no',
'question_category' => array(
'' => esc_html__( 'Select a category', 'learndash' ),
),
)
);
if ( ( is_admin() ) && ( isset( $_GET['page'] ) ) && ( 'questions-options' === $_GET['page'] ) ) {
$category_mapper = new WpProQuiz_Model_CategoryMapper();
$question_categories = $category_mapper->fetchAll();
if ( ( ! empty( $question_categories ) ) && ( is_array( $question_categories ) ) ) {
foreach ( $question_categories as $question_category ) {
$category_name = $question_category->getCategoryName();
$category_id = $question_category->getCategoryId();
if ( ! empty( $category_name ) ) {
$this->setting_option_values['question_category'][ $category_id ] = esc_html( $category_name );
}
}
}
}
}
/**
* Initialize the metabox settings fields.
*/
public function load_settings_fields() {
$this->setting_option_fields = array(
/*
'ld_question_category' => array(
'name' => 'ld_question_category',
'type' => 'checkbox',
'label' => sprintf(
// translators: placeholder: Question.
esc_html_x( 'LearnDash %s Categories', 'placeholder: Question', 'learndash' ),
LearnDash_Custom_Label::get_label( 'question' )
),
'help_text' => sprintf(
// translators: placeholder: Question.
esc_html_x( 'Enable the builtin LearnDash %s Categories', 'placeholder: Question', 'learndash' ),
LearnDash_Custom_Label::get_label( 'question' )
),
'value' => $this->setting_option_values['ld_question_category'],
'options' => array(
'yes' => esc_html__( 'Yes', 'learndash' ),
),
),
*/
/*
'ld_question_tag' => array(
'name' => 'ld_question_tag',
'type' => 'checkbox',
'label' => sprintf(
// translators: placeholder: Question.
esc_html_x( 'LearnDash %s Tags', 'placeholder: Question', 'learndash' ),
LearnDash_Custom_Label::get_label( 'question' )
),
'help_text' => sprintf(
// translators: placeholder: Quiz.
esc_html_x( 'Enable the builtin LearnDash %s Tags', 'placeholder: Question', 'learndash' ),
LearnDash_Custom_Label::get_label( 'question' )
),
'value' => $this->setting_option_values['ld_question_tag'],
'options' => array(
'yes' => esc_html__( 'Yes', 'learndash' ),
),
),
*/
/*
'wp_post_category' => array(
'name' => 'wp_post_category',
'type' => 'checkbox',
'label' => esc_html__( 'WordPress Post Categories', 'learndash' ),
'help_text' => esc_html__( 'Enable the builtin WordPress Post Categories', 'learndash' ),
'value' => $this->setting_option_values['wp_post_category'],
'options' => array(
'yes' => esc_html__( 'Yes', 'learndash' ),
),
),
*/
/*
'wp_post_tag' => array(
'name' => 'wp_post_tag',
'type' => 'checkbox',
'label' => esc_html__( 'WordPress Post Tags', 'learndash' ),
'help_text' => esc_html__( 'Enable the builtin WordPress Post Tags', 'learndash' ),
'value' => $this->setting_option_values['wp_post_tag'],
'options' => array(
'yes' => esc_html__( 'Yes', 'learndash' ),
),
),
*/
'proquiz_question_category' => array(
'name' => 'proquiz_question_category',
'type' => 'checkbox-switch',
'label' => sprintf(
// translators: placeholder: Question.
esc_html_x( '%s Categories', 'placeholder: Question', 'learndash' ),
LearnDash_Custom_Label::get_label( 'question' )
),
'value' => $this->setting_option_values['proquiz_question_category'],
'options' => array(
'yes' => esc_html__( 'Yes', 'learndash' ),
),
'options' => array(
'yes' => array(
'tooltip' => sprintf(
// translators: placeholder: Question.
esc_html_x( '%s categories cannot be disabled.', 'placeholder: Question', 'learndash' ),
learndash_get_custom_label( 'question' )
),
),
),
'child_section_state' => ( 'yes' === $this->setting_option_values['proquiz_question_category'] ) ? 'open' : 'closed',
'attrs' => array(
'disabled' => 'disabled',
),
),
'_question_category' => array(
'name' => 'question_category',
'type' => 'select-edit-delete',
'label' => esc_html__( 'Category management', 'learndash' ),
'help_text' => esc_html__( 'Select a category to update or delete the title.', 'learndash' ),
'value' => '',
'options' => $this->setting_option_values['question_category'],
'buttons' => array(
'delete' => esc_html__( 'Delete', 'learndash' ),
'update' => esc_html__( 'Update', 'learndash' ),
),
'parent_setting' => 'proquiz_question_category',
),
);
$this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_section_key );
parent::load_settings_fields();
}
/**
* This function handles the AJAX actions from the browser.
*
* @since 2.5.9
*/
public function ajax_action() {
$reply_data = array( 'status' => false );
if ( current_user_can( 'wpProQuiz_edit_quiz' ) ) {
if ( ( isset( $_POST['field_nonce'] ) ) && ( ! empty( $_POST['field_nonce'] ) ) && ( isset( $_POST['field_key'] ) ) && ( ! empty( $_POST['field_key'] ) ) && ( wp_verify_nonce( esc_attr( $_POST['field_nonce'] ), $_POST['field_key'] ) ) ) {
if ( isset( $_POST['field_action'] ) ) {
if ( 'update' === $_POST['field_action'] ) {
if ( ( isset( $_POST['field_value'] ) ) && ( ! empty( $_POST['field_value'] ) ) && ( isset( $_POST['field_text'] ) ) && ( ! empty( $_POST['field_text'] ) ) ) {
$category_id = intval( $_POST['field_value'] );
$category_new_name = esc_attr( $_POST['field_text'] );
$category_mapper = new WpProQuiz_Model_CategoryMapper();
$category = $category_mapper->fetchById( $category_id );
if ( ( $category ) && ( is_a( $category, 'WpProQuiz_Model_Category' ) ) ) {
$category_current_name = $category->getCategoryName();
if ( $category_current_name !== $category_new_name ) {
$update_ret = $category_mapper->updateCatgoryName( $category_id, $category_new_name );
if ( $update_ret ) {
$reply_data['status'] = true;
$reply_data['message'] = '' . __( 'Category updated.', 'learndash' ) . '';
}
}
}
}
} elseif ( 'delete' === $_POST['field_action'] ) {
if ( ( isset( $_POST['field_value'] ) ) && ( ! empty( $_POST['field_value'] ) ) ) {
$category_id = intval( $_POST['field_value'] );
$category_mapper = new WpProQuiz_Model_CategoryMapper();
$category = $category_mapper->fetchById( $category_id );
if ( ( $category ) && ( is_a( $category, 'WpProQuiz_Model_Category' ) ) ) {
$update_ret = $category_mapper->delete( $category_id );
if ( $update_ret ) {
$reply_data['status'] = true;
$reply_data['message'] = '' . __( 'Category deleted.', 'learndash' ) . '';
}
}
}
}
}
}
}
if ( ! empty( $reply_data ) ) {
echo wp_json_encode( $reply_data );
}
wp_die(); // This is required to terminate immediately and return a proper response.
}
// End of functions.
}
}
add_action(
'learndash_settings_sections_init',
function() {
LearnDash_Settings_Questions_Taxonomies::add_section_instance();
}
);
settings-sections/class-ld-settings-section-quizzes-taxonomies.php 0000666 00000012211 15214240575 0021646 0 ustar 00 settings_screen_id = 'sfwd-quiz_page_quizzes-options';
// The page ID (different than the screen ID).
$this->settings_page_id = 'quizzes-options';
// This is the 'option_name' key used in the wp_options table.
$this->setting_option_key = 'learndash_settings_quizzes_taxonomies';
// This is the HTML form field prefix used.
$this->setting_field_prefix = 'learndash_settings_quizzes_taxonomies';
// Used within the Settings API to uniquely identify this section.
$this->settings_section_key = 'taxonomies';
// Section label/header.
$this->settings_section_label = sprintf(
// translators: placeholder: Quiz.
esc_html_x( '%s Taxonomies', 'placeholder: Quiz', 'learndash' ),
learndash_get_custom_label( 'quiz' )
);
// Used to show the section description above the fields. Can be empty.
$this->settings_section_description = sprintf(
// translators: placeholder: quizzes.
esc_html_x( 'Control which Taxonomies can be used with the LearnDash %s.', 'placeholder: quizzes', 'learndash' ),
learndash_get_custom_label_lower( 'quizzes' )
);
parent::__construct();
}
/**
* Initialize the metabox settings values.
*/
public function load_settings_values() {
parent::load_settings_values();
$_init = false;
if ( false === $this->setting_option_values ) {
$_init = true;
$this->setting_option_values = array(
'ld_quiz_category' => '',
'ld_quiz_tag' => '',
'wp_post_category' => '',
'wp_post_tag' => '',
);
// If this is a new install we want to turn off WP Post Category/Tag.
$ld_prior_version = learndash_data_upgrades_setting( 'prior_version' );
if ( 'new' === $ld_prior_version ) {
$this->setting_option_values['ld_quiz_category'] = '';
$this->setting_option_values['ld_quiz_tag'] = '';
$this->setting_option_values['wp_post_category'] = '';
$this->setting_option_values['wp_post_tag'] = '';
}
}
$this->setting_option_values = wp_parse_args(
$this->setting_option_values,
array(
'ld_quiz_category' => '',
'ld_quiz_tag' => '',
'wp_post_category' => '',
'wp_post_tag' => '',
)
);
}
/**
* Initialize the metabox settings fields.
*/
public function load_settings_fields() {
$this->setting_option_fields = array(
'ld_quiz_category' => array(
'name' => 'ld_quiz_category',
'type' => 'checkbox-switch',
'label' => sprintf(
// translators: placeholder: Quiz.
esc_html_x( '%s Categories', 'placeholder: Quiz', 'learndash' ),
learndash_get_custom_label( 'quiz' )
),
'value' => $this->setting_option_values['ld_quiz_category'],
'options' => array(
'' => '',
'yes' => sprintf(
// translators: placeholder: Quiz.
esc_html_x( 'Manage %s Categories via the Actions dropdown', 'placeholder: Quiz', 'learndash' ),
learndash_get_custom_label( 'quiz' )
),
),
),
'ld_quiz_tag' => array(
'name' => 'ld_quiz_tag',
'type' => 'checkbox-switch',
'label' => sprintf(
// translators: placeholder: Quiz.
esc_html_x( '%s Tags', 'placeholder: Quiz', 'learndash' ),
learndash_get_custom_label( 'quiz' )
),
'value' => $this->setting_option_values['ld_quiz_tag'],
'options' => array(
'' => '',
'yes' => sprintf(
// translators: placeholder: Quiz.
esc_html_x( 'Manage %s Tags via the Actions dropdown', 'placeholder: Quiz', 'learndash' ),
learndash_get_custom_label( 'quiz' )
),
),
),
'wp_post_category' => array(
'name' => 'wp_post_category',
'type' => 'checkbox-switch',
'label' => esc_html__( 'WP Post Categories', 'learndash' ),
'value' => $this->setting_option_values['wp_post_category'],
'options' => array(
'' => '',
'yes' => esc_html__( 'Manage WP Categories via the Actions dropdown', 'learndash' ),
),
),
'wp_post_tag' => array(
'name' => 'wp_post_tag',
'type' => 'checkbox-switch',
'label' => esc_html__( 'WP Post Tags', 'learndash' ),
'value' => $this->setting_option_values['wp_post_tag'],
'options' => array(
'' => '',
'yes' => esc_html__( 'Manage WP Tags via the Actions dropdown', 'learndash' ),
),
),
);
$this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_section_key );
parent::load_settings_fields();
}
}
}
add_action(
'learndash_settings_sections_init',
function() {
LearnDash_Settings_Quizzes_Taxonomies::add_section_instance();
}
);
settings-sections/class-ld-settings-section-questions-cpt.php 0000666 00000005132 15214240575 0020572 0 ustar 00 settings_screen_id = 'sfwd-question_page_questions-options';
// The page ID (different than the screen ID).
$this->settings_page_id = 'questions-options';
// This is the 'option_name' key used in the wp_options table.
$this->setting_option_key = 'learndash_settings_questions_cpt';
// This is the HTML form field prefix used.
$this->setting_field_prefix = 'learndash_settings_questions_cpt';
// Used within the Settings API to uniquely identify this section.
$this->settings_section_key = 'cpt_options';
// Section label/header.
$this->settings_section_label = sprintf(
// translators: placeholder: Quiz.
esc_html_x( '%s Custom Post Type Options', 'placeholder: Question', 'learndash' ),
LearnDash_Custom_Label::get_label( 'question' )
);
// Used to show the section description above the fields. Can be empty.
$this->settings_section_description = sprintf(
wp_kses_post(
// translators: placeholder: Quizzes.
_x( 'Control the LearnDash %s Custom Post Type Options.
', 'placeholder: Questions', 'learndash' ) ), LearnDash_Custom_Label::get_label( 'questions' ) ); parent::__construct(); } /** * Initialize the metabox settings fields. */ public function load_settings_fields() { $this->setting_option_fields = array( 'exclude_from_search' => array( 'name' => 'exclude_from_search', 'type' => 'checkbox', 'label' => esc_html__( 'Exclude From Search', 'learndash' ), 'help_text' => esc_html__( 'Exclude From Search', 'learndash' ), 'value' => isset( $this->setting_option_values['exclude_from_search'] ) ? $this->setting_option_values['exclude_from_search'] : '', 'options' => array( 'yes' => esc_html__( 'Exclude', 'learndash' ), ), ), ); $this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_section_key ); parent::load_settings_fields(); } } } add_action( 'learndash_settings_sections_init', function() { LearnDash_Settings_Questions_CPT::add_section_instance(); } ); settings-sections/class-ld-settings-section-topics-cpt.php 0000666 00000020652 15214240575 0020045 0 ustar 00 settings_screen_id = 'sfwd-topic_page_topics-options'; // The page ID (different than the screen ID). $this->settings_page_id = 'topics-options'; // This is the 'option_name' key used in the wp_options table. $this->setting_option_key = 'learndash_settings_topics_cpt'; // This is the HTML form field prefix used. $this->setting_field_prefix = 'learndash_settings_topics_cpt'; // Used within the Settings API to uniquely identify this section. $this->settings_section_key = 'cpt_options'; // Section label/header. $this->settings_section_label = sprintf( // translators: placeholder: Lesson. esc_html_x( '%s Custom Post Type Options', 'placeholder: Lesson', 'learndash' ), LearnDash_Custom_Label::get_label( 'topic' ) ); // Used to show the section description above the fields. Can be empty. $this->settings_section_description = sprintf( // translators: placeholder: Topics. esc_html_x( 'Control the LearnDash %s Custom Post Type Options.', 'placeholder: Topics', 'learndash' ), LearnDash_Custom_Label::get_label( 'topics' ) ); parent::__construct(); } /** * Initialize the metabox settings values. */ public function load_settings_values() { parent::load_settings_values(); if ( ( false === $this->setting_option_values ) || ( '' === $this->setting_option_values ) ) { if ( '' === $this->setting_option_values ) { $this->setting_option_values = array(); } $this->setting_option_values = array( 'include_in_search' => 'yes', 'has_archive' => '', 'has_feed' => '', 'supports' => array( 'thumbnail', 'revisions' ), ); } if ( ! isset( $this->setting_option_values['include_in_search'] ) ) { if ( ( isset( $this->setting_option_values['exclude_from_search'] ) ) && ( 'yes' === $this->setting_option_values['exclude_from_search'] ) ) { $this->setting_option_values['include_in_search'] = ''; } else { $this->setting_option_values['include_in_search'] = 'yes'; } } if ( ! isset( $this->setting_option_values['has_archive'] ) ) { $this->setting_option_values['has_archive'] = 'yes'; } if ( ! isset( $this->setting_option_values['has_feed'] ) ) { $this->setting_option_values['has_feed'] = ''; } if ( ! isset( $this->setting_option_values['supports'] ) ) { $this->setting_option_values['supports'] = array( 'thumbnail', 'revisions' ); } } /** * Initialize the metabox settings fields. */ public function load_settings_fields() { $cpt_archive_url = home_url( LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Section_Permalinks', 'topics' ) ); $cpt_rss_url = add_query_arg( 'post_type', 'sfwd-topic', get_post_type_archive_feed_link( 'post' ) ); $this->setting_option_fields = array( 'include_in_search' => array( 'name' => 'include_in_search', 'type' => 'checkbox-switch', 'label' => sprintf( // translators: placeholder: Topic. esc_html_x( '%s Search', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ), 'help_text' => sprintf( // translators: placeholder: topic. esc_html_x( 'Includes the %s post type in front end search results', 'placeholder: topic', 'learndash' ), learndash_get_custom_label_lower( 'topic' ) ), 'value' => $this->setting_option_values['include_in_search'], 'options' => array( 'yes' => '', ), ), 'has_archive' => array( 'name' => 'has_archive', 'type' => 'checkbox-switch', 'label' => esc_html__( 'Archive Page', 'learndash' ), 'help_text' => sprintf( // translators: placeholder: topics, link to WP Permalins page. esc_html_x( 'Enables the front end archive page where all %1$s are listed. You must %2$s for the change to take effect.', 'placeholder: topics, link to WP Permalins page', 'learndash' ), learndash_get_custom_label_lower( 'topics' ), '' . esc_html__( 're-save your permalinks', 'learndash' ) . '' ), 'value' => $this->setting_option_values['has_archive'], 'options' => array( '' => '', 'yes' => sprintf( // translators: placeholder: URL for CPT Archive. esc_html_x( 'Archive URL: %s', 'placeholder: URL for CPT Archive', 'learndash' ), '' . $cpt_archive_url . ''
),
),
'child_section_state' => ( 'yes' === $this->setting_option_values['has_archive'] ) ? 'open' : 'closed',
),
'has_feed' => array(
'name' => 'has_feed',
'type' => 'checkbox-switch',
'label' => esc_html__( 'RSS/Atom Feed', 'learndash' ),
'help_text' => sprintf(
// translators: placeholder: topic
esc_html_x( 'Enables an RSS feed for all %1$s posts.', 'placeholder: topic', 'learndash' ),
learndash_get_custom_label_lower( 'topic' )
),
'value' => $this->setting_option_values['has_feed'],
'options' => array(
'' => '',
'yes' => sprintf(
// translators: placeholder: URL for CPT Archive.
esc_html_x( 'RSS Feed URL: %s', 'placeholder: URL for RSS Feed', 'learndash' ),
'' . $cpt_rss_url . ''
),
),
'parent_setting' => 'has_archive',
),
'supports' => array(
'name' => 'supports',
'type' => 'checkbox',
'label' => esc_html__( 'Editor Supported Settings', 'learndash' ),
'help_text' => esc_html__( 'Enables WordPress supported settings within the editor and theme.', 'learndash' ),
'value' => $this->setting_option_values['supports'],
'options' => array(
'thumbnail' => esc_html__( 'Featured image', 'learndash' ),
'comments' => esc_html__( 'Comments', 'learndash' ),
'custom-fields' => esc_html__( 'Custom Fields', 'learndash' ),
'revisions' => esc_html__( 'Revisions', 'learndash' ),
),
),
);
$this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_section_key );
parent::load_settings_fields();
}
/**
* Intercept the WP options save logic and check that we have a valid nonce.
*
* @since 3.0
* @param array $value Array of section fields values.
* @param array $old_value Array of old values.
* @param string $section_key Section option key should match $this->setting_option_key.
*/
public function section_pre_update_option( $new_values = '', $old_values = '', $setting_option_key = '' ) {
if ( $setting_option_key === $this->setting_option_key ) {
$new_values = parent::section_pre_update_option( $new_values, $old_values, $setting_option_key );
if ( ! isset( $new_values['include_in_search'] ) ) {
$new_values['include_in_search'] = '';
}
if ( ! isset( $new_values['has_archive'] ) ) {
$new_values['has_archive'] = '';
$new_values['has_feed'] = '';
}
if ( ! isset( $new_values['has_feed'] ) ) {
$new_values['has_feed'] = '';
}
if ( ! isset( $new_values['supports'] ) ) {
$new_values['supports'] = array();
}
if ( $new_values !== $old_values ) {
if ( ( ! isset( $old_values['has_archive'] ) ) || ( $new_values['has_archive'] !== $old_values['has_archive'] ) ) {
learndash_setup_rewrite_flush();
}
//if ( in_array( 'comments', $new_values['supports'] ) ) {
// learndash_update_posts_comment_status( 'sfwd-topic', 'open' );
//} else {
// learndash_update_posts_comment_status( 'sfwd-topic', 'closed' );
//}
}
}
return $new_values;
}
// End of functions.
}
}
add_action(
'learndash_settings_sections_init',
function() {
LearnDash_Settings_Topics_CPT::add_section_instance();
}
);
settings-sections/class-ld-settings-section-custom-labels.php 0000666 00000020241 15214240575 0020524 0 ustar 00 settings_page_id = 'learndash_lms_settings_custom_labels';
// This is the 'option_name' key used in the wp_options table.
$this->setting_option_key = 'learndash_settings_custom_labels';
// This is the HTML form field prefix used.
$this->setting_field_prefix = 'learndash_settings_custom_labels';
// Used within the Settings API to uniquely identify this section.
$this->settings_section_key = 'settings_custom_labels';
// Section label/header.
$this->settings_section_label = esc_html__( 'Custom Labels', 'learndash' );
$this->reset_confirm_message = esc_html__( 'Are you sure want to reset the custom labels?', 'learndash' );
parent::__construct();
}
/**
* Initialize the metabox settings values.
*/
public function load_settings_values() {
parent::load_settings_values();
if ( false === $this->setting_option_values ) {
$this->setting_option_values = get_option( 'learndash_custom_label_settings' );
}
if ( ( isset( $_GET['action'] ) ) && ( 'ld_reset_settings' === $_GET['action'] ) && ( isset( $_GET['page'] ) ) && ( $_GET['page'] === $this->settings_page_id ) ) {
if ( ( isset( $_GET['ld_wpnonce'] ) ) && ( ! empty( $_GET['ld_wpnonce'] ) ) ) {
if ( wp_verify_nonce( $_GET['ld_wpnonce'], get_current_user_id() . '-' . $this->setting_option_key ) ) {
if ( ! empty( $this->setting_option_values ) ) {
foreach ( $this->setting_option_values as $key => $val ) {
$this->setting_option_values[ $key ] = '';
}
$this->save_settings_values();
}
$reload_url = remove_query_arg( array( 'action', 'ld_wpnonce' ) );
wp_safe_redirect( $reload_url );
die();
}
}
}
}
/**
* Initialize the metabox settings fields.
*/
public function load_settings_fields() {
$this->setting_option_fields = array(
'course' => array(
'name' => 'course',
'type' => 'text',
'label' => esc_html__( 'Course', 'learndash' ),
'help_text' => esc_html__( 'Label to replace "course" (singular).', 'learndash' ),
'value' => isset( $this->setting_option_values['course'] ) ? $this->setting_option_values['course'] : '',
'class' => 'regular-text',
),
'courses' => array(
'name' => 'courses',
'type' => 'text',
'label' => esc_html__( 'Courses', 'learndash' ),
'help_text' => esc_html__( 'Label to replace "courses" (plural).', 'learndash' ),
'value' => isset( $this->setting_option_values['courses'] ) ? $this->setting_option_values['courses'] : '',
'class' => 'regular-text',
),
'lesson' => array(
'name' => 'lesson',
'type' => 'text',
'label' => esc_html__( 'Lesson', 'learndash' ),
'help_text' => esc_html__( 'Label to replace "lesson" (singular).', 'learndash' ),
'value' => isset( $this->setting_option_values['lesson'] ) ? $this->setting_option_values['lesson'] : '',
'class' => 'regular-text',
),
'lessons' => array(
'name' => 'lessons',
'type' => 'text',
'label' => esc_html__( 'Lessons', 'learndash' ),
'help_text' => esc_html__( 'Label to replace "lessons" (plural).', 'learndash' ),
'value' => isset( $this->setting_option_values['lessons'] ) ? $this->setting_option_values['lessons'] : '',
'class' => 'regular-text',
),
'topic' => array(
'name' => 'topic',
'type' => 'text',
'label' => esc_html__( 'Topic', 'learndash' ),
'help_text' => esc_html__( 'Label to replace "topic" (singular).', 'learndash' ),
'value' => isset( $this->setting_option_values['topic'] ) ? $this->setting_option_values['topic'] : '',
'class' => 'regular-text',
),
'topics' => array(
'name' => 'topics',
'type' => 'text',
'label' => esc_html__( 'Topics', 'learndash' ),
'help_text' => esc_html__( 'Label to replace "topics" (plural).', 'learndash' ),
'value' => isset( $this->setting_option_values['topics'] ) ? $this->setting_option_values['topics'] : '',
'class' => 'regular-text',
),
'quiz' => array(
'name' => 'quiz',
'type' => 'text',
'label' => esc_html__( 'Quiz', 'learndash' ),
'help_text' => esc_html__( 'Label to replace "quiz" (singular).', 'learndash' ),
'value' => isset( $this->setting_option_values['quiz'] ) ? $this->setting_option_values['quiz'] : '',
'class' => 'regular-text',
),
'quizzes' => array(
'name' => 'quizzes',
'type' => 'text',
'label' => esc_html__( 'Quizzes', 'learndash' ),
'help_text' => esc_html__( 'Label to replace "quizzes" (plural).', 'learndash' ),
'value' => isset( $this->setting_option_values['quizzes'] ) ? $this->setting_option_values['quizzes'] : '',
'class' => 'regular-text',
),
'question' => array(
'name' => 'question',
'type' => 'text',
'label' => esc_html__( 'Question', 'learndash' ),
'help_text' => esc_html__( 'Label to replace "question" (singular).', 'learndash' ),
'value' => isset( $this->setting_option_values['question'] ) ? $this->setting_option_values['question'] : '',
'class' => 'regular-text',
),
'questions' => array(
'name' => 'questions',
'type' => 'text',
'label' => esc_html__( 'Questions', 'learndash' ),
'help_text' => esc_html__( 'Label to replace "questions" (plural).', 'learndash' ),
'value' => isset( $this->setting_option_values['questions'] ) ? $this->setting_option_values['questions'] : '',
'class' => 'regular-text',
),
'button_take_this_course' => array(
'name' => 'button_take_this_course',
'type' => 'text',
'label' => esc_html__( 'Take this Course (Button)', 'learndash' ),
'help_text' => esc_html__( 'Label to replace "Take this Course" button.', 'learndash' ),
'value' => isset( $this->setting_option_values['button_take_this_course'] ) ? $this->setting_option_values['button_take_this_course'] : '',
'class' => 'regular-text',
),
'button_mark_complete' => array(
'name' => 'button_mark_complete',
'type' => 'text',
'label' => esc_html__( 'Mark Complete (Button)', 'learndash' ),
'help_text' => esc_html__( 'Label to replace "Mark Complete" button.', 'learndash' ),
'value' => isset( $this->setting_option_values['button_mark_complete'] ) ? $this->setting_option_values['button_mark_complete'] : '',
'class' => 'regular-text',
),
'button_click_here_to_continue' => array(
'name' => 'button_click_here_to_continue',
'type' => 'text',
'label' => esc_html__( 'Click Here to Continue (Button)', 'learndash' ),
'help_text' => esc_html__( 'Label to replace "Click Here to Continue" button.', 'learndash' ),
'value' => isset( $this->setting_option_values['button_click_here_to_continue'] ) ? $this->setting_option_values['button_click_here_to_continue'] : '',
'class' => 'regular-text',
),
);
// Legacy custom labels filter.
$this->setting_option_fields = apply_filters( 'learndash_custom_label_fields', $this->setting_option_fields );
$this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_section_key );
parent::load_settings_fields();
}
}
}
add_action(
'learndash_settings_sections_init',
function() {
LearnDash_Settings_Section_Custom_Labels::add_section_instance();
}
);
settings-sections/class-ld-settings-section-general-login-registration.php 0000666 00000007710 15214240575 0023213 0 ustar 00 settings_page_id = 'learndash_lms_settings';
// This is the 'option_name' key used in the wp_options table.
$this->setting_option_key = 'learndash_settings_login_registration';
// This is the HTML form field prefix used.
$this->setting_field_prefix = 'learndash_settings_login_registration';
// Used within the Settings API to uniquely identify this section.
$this->settings_section_key = 'settings_login_registration';
// Section label/header.
$this->settings_section_label = esc_html__( 'Login / Registration Settings', 'learndash' );
parent::__construct();
}
/**
* Initialize the metabox settings values.
*/
public function load_settings_values() {
parent::load_settings_values();
if ( ! isset( $this->setting_option_values['login_logo'] ) ) {
$this->setting_option_values['login_logo'] = 0;
}
if ( ! isset( $this->setting_option_values['login_logo2'] ) ) {
$this->setting_option_values['login_logo2'] = 0;
}
}
/**
* Initialize the metabox settings fields.
*/
public function load_settings_fields() {
$this->setting_option_fields = array(
'login_logo' => array(
'name' => 'login_logo',
'type' => 'media-upload',
'label' => esc_html__( 'Login Logo', 'learndash' ),
/*
'help_text' => sprintf(
// translators: placeholder: Default per page number.
esc_html_x( 'Default per page controls all shortcodes and widget. Default is %d. Set to zero for no pagination.', 'placeholder: Default per page', 'learndash' ),
LEARNDASH_LMS_DEFAULT_WIDGET_PER_PAGE
),
*/
'value' => $this->setting_option_values['login_logo'],
'validate_callback' => array( $this, 'validate_section_field_media_upload' ),
'validate_args' => array(
'allow_empty' => 1,
),
),
'login_logo2' => array(
'name' => 'login_logo2',
'type' => 'media-upload',
'label' => esc_html__( 'Login Logo 2', 'learndash' ),
'help_text' => sprintf(
// translators: placeholder: Default per page number.
esc_html_x( 'Default per page controls all shortcodes and widget. Default is %d. Set to zero for no pagination.', 'placeholder: Default per page', 'learndash' ),
LEARNDASH_LMS_DEFAULT_WIDGET_PER_PAGE
),
'value' => $this->setting_option_values['login_logo2'],
'validate_callback' => array( $this, 'validate_section_field_media_upload' ),
'validate_args' => array(
'allow_empty' => 1,
),
),
);
$this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_section_key );
parent::load_settings_fields();
}
/**
* Validate settings field.
*
* @param string $val Value to be validated.
* @param string $key settings fields key.
* @param array $args Settings field args array.
*
* @return integer $val.
*/
public function validate_section_field_media_upload( $val, $key, $args = array() ) {
// Get the digits only.
$val = absint( $val );
if ( ( isset( $args['field']['validate_args']['allow_empty'] ) ) && ( true === $args['field']['validate_args']['allow_empty'] ) && ( empty( $val ) ) ) {
$val = '';
}
return $val;
}
// End of functions.
}
}
add_action(
'learndash_settings_sections_init',
function() {
LearnDash_Settings_Section_General_Login_Registration::add_section_instance();
}
);
settings-sections/class-ld-settings-section-topics-taxonomies.php 0000666 00000012075 15214240575 0021445 0 ustar 00 settings_screen_id = 'sfwd-topic_page_topics-options';
// The page ID (different than the screen ID).
$this->settings_page_id = 'topics-options';
// This is the 'option_name' key used in the wp_options table.
$this->setting_option_key = 'learndash_settings_topics_taxonomies';
// This is the HTML form field prefix used.
$this->setting_field_prefix = 'learndash_settings_topics_taxonomies';
// Used within the Settings API to uniquely identify this section.
$this->settings_section_key = 'taxonomies';
// Section label/header.
$this->settings_section_label = sprintf(
// translators: placeholder: Topic.
esc_html_x( '%s Taxonomies', 'placeholder: Topic', 'learndash' ),
learndash_get_custom_label( 'topic' )
);
// Used to show the section description above the fields. Can be empty.
$this->settings_section_description = sprintf(
// translators: placeholder: topics.
esc_html_x( 'Control which Taxonomies can be used with the LearnDash %s.', 'placeholder: topics', 'learndash' ),
LearnDash_Custom_Label::get_label( 'topics' )
);
parent::__construct();
}
/**
* Initialize the metabox settings values.
*/
public function load_settings_values() {
parent::load_settings_values();
$_init = false;
if ( false === $this->setting_option_values ) {
$__init = true;
$this->setting_option_values = array(
'ld_topic_category' => 'yes',
'ld_topic_tag' => 'yes',
'wp_post_category' => '',
'wp_post_tag' => '',
);
// If this is a new install we want to turn off WP Post Category/Tag.
$ld_prior_version = learndash_data_upgrades_setting( 'prior_version' );
if ( 'new' === $ld_prior_version ) {
$this->setting_option_values['wp_post_category'] = '';
$this->setting_option_values['wp_post_tag'] = '';
}
}
$this->setting_option_values = wp_parse_args(
$this->setting_option_values,
array(
'ld_topic_category' => '',
'ld_topic_tag' => '',
'wp_post_category' => '',
'wp_post_tag' => '',
)
);
}
/**
* Initialize the metabox settings fields.
*/
public function load_settings_fields() {
$this->setting_option_fields = array(
'ld_topic_category' => array(
'name' => 'ld_topic_category',
'type' => 'checkbox-switch',
'label' => sprintf(
// translators: placeholder: Topic.
esc_html_x( '%s Categories', 'placeholder: Topic', 'learndash' ),
LearnDash_Custom_Label::get_label( 'topic' )
),
'value' => $this->setting_option_values['ld_topic_category'],
'options' => array(
'' => '',
'yes' => sprintf(
// translators: placeholder: Topic.
esc_html_x( 'Manage %s Categories via the Actions dropdown', 'placeholder: Topic', 'learndash' ),
learndash_get_custom_label( 'topic' )
),
),
),
'ld_topic_tag' => array(
'name' => 'ld_topic_tag',
'type' => 'checkbox-switch',
'label' => sprintf(
// translators: placeholder: Topic.
esc_html_x( '%s Tags', 'placeholder: Topic', 'learndash' ),
LearnDash_Custom_Label::get_label( 'topic' )
),
'value' => $this->setting_option_values['ld_topic_tag'],
'options' => array(
'' => '',
'yes' => sprintf(
// translators: placeholder: Topic.
esc_html_x( 'Manage %s Tags via the Actions dropdown', 'placeholder: Topic', 'learndash' ),
learndash_get_custom_label( 'topic' )
),
),
),
'wp_post_category' => array(
'name' => 'wp_post_category',
'type' => 'checkbox-switch',
'label' => esc_html__( 'WP Post Categories', 'learndash' ),
'value' => $this->setting_option_values['wp_post_category'],
'options' => array(
'' => '',
'yes' => esc_html__( 'Manage WP Categories via the Actions dropdown', 'learndash' ),
),
),
'wp_post_tag' => array(
'name' => 'wp_post_tag',
'type' => 'checkbox-switch',
'label' => esc_html__( 'WP Post Tags', 'learndash' ),
'value' => $this->setting_option_values['wp_post_tag'],
'options' => array(
'' => '',
'yes' => esc_html__( 'Manage WP Tags via the Actions dropdown', 'learndash' ),
),
),
);
$this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_section_key );
parent::load_settings_fields();
}
}
}
add_action(
'learndash_settings_sections_init',
function() {
LearnDash_Settings_Topics_Taxonomies::add_section_instance();
}
);
settings-sections/class-ld-settings-section-paypal.php 0000666 00000023674 15214240575 0017255 0 ustar 00 settings_page_id = 'learndash_lms_settings_paypal';
// This is the 'option_name' key used in the wp_options table.
$this->setting_option_key = 'learndash_settings_paypal';
// This is the HTML form field prefix used.
$this->setting_field_prefix = 'learndash_settings_paypal';
// Used within the Settings API to uniquely identify this section.
$this->settings_section_key = 'settings_paypal';
// Section label/header.
$this->settings_section_label = esc_html__( 'PayPal Settings', 'learndash' );
$this->reset_confirm_message = esc_html__( 'Are you sure want to reset the PayPal values?', 'learndash' );
parent::__construct();
}
/**
* Initialize the metabox settings values.
*/
public function load_settings_values() {
parent::load_settings_values();
if ( false === $this->setting_option_values ) {
$sfwd_cpt_options = get_option( 'sfwd_cpt_options' );
if ( ( isset( $sfwd_cpt_options['modules']['sfwd-courses_options'] ) ) && ( ! empty( $sfwd_cpt_options['modules']['sfwd-courses_options'] ) ) ) {
foreach ( $sfwd_cpt_options['modules']['sfwd-courses_options'] as $key => $val ) {
$key = str_replace( 'sfwd-courses_', '', $key );
if ( 'paypal_sandbox' === $key ) {
if ( 'on' === $val ) {
$val = 'yes';
} else {
$val = 'no';
}
}
$this->setting_option_values[ $key ] = $val;
}
}
}
if ( ( isset( $_GET['action'] ) ) && ( 'ld_reset_settings' === $_GET['action'] ) && ( isset( $_GET['page'] ) ) && ( $_GET['page'] == $this->settings_page_id ) ) {
if ( ( isset( $_GET['ld_wpnonce'] ) ) && ( ! empty( $_GET['ld_wpnonce'] ) ) ) {
if ( wp_verify_nonce( $_GET['ld_wpnonce'], get_current_user_id() . '-' . $this->setting_option_key ) ) {
if ( ! empty( $this->setting_option_values ) ) {
foreach ( $this->setting_option_values as $key => $val ) {
$this->setting_option_values[ $key ] = '';
}
$this->save_settings_values();
}
$reload_url = remove_query_arg( array( 'action', 'ld_wpnonce' ) );
wp_redirect( $reload_url );
die();
}
}
}
}
/**
* Initialize the metabox settings fields.
*/
public function load_settings_fields() {
global $wp_rewrite;
if ( ( isset( $wp_rewrite ) ) && ( $wp_rewrite->using_permalinks() ) ) {
$default_paypal_notifyurl = trailingslashit( get_home_url() ) . 'sfwd-lms/paypal';
} else {
$default_paypal_notifyurl = add_query_arg( 'sfwd-lms', 'paypal', get_home_url() );
}
$this->setting_option_fields = array(
'paypal_email' => array(
'name' => 'paypal_email',
'type' => 'text',
'label' => esc_html__( 'PayPal Email', 'learndash' ),
'help_text' => esc_html__( 'Enter your PayPal email here.', 'learndash' ),
'value' => ( ( isset( $this->setting_option_values['paypal_email'] ) ) && ( ! empty( $this->setting_option_values['paypal_email'] ) ) ) ? $this->setting_option_values['paypal_email'] : '',
'class' => 'regular-text',
'validate_callback' => array( $this, 'validate_section_paypal_email' ),
),
'paypal_currency' => array(
'name' => 'paypal_currency',
'type' => 'text',
'label' => esc_html__( 'PayPal Currency', 'learndash' ),
'help_text' => sprintf(
// translators: placholder: Link to PayPal.
esc_html_x( 'Enter the currency code for transactions. See PayPal %s Documentation', 'placeholder: URL to PayPal Currency Codes', 'learndash' ),
'' . __( 'Currency Codes', 'learndash' ) . ''
),
'value' => ( ( isset( $this->setting_option_values['paypal_currency'] ) ) && ( ! empty( $this->setting_option_values['paypal_currency'] ) ) ) ? $this->setting_option_values['paypal_currency'] : 'USD',
'class' => 'regular-text',
'validate_callback' => array( $this, 'validate_section_paypal_currency' ),
),
'paypal_country' => array(
'name' => 'paypal_country',
'type' => 'text',
'label' => esc_html__( 'PayPal Country', 'learndash' ),
'help_text' => sprintf(
// translators: placeholder: Link to PayPal Country Codes.
esc_html_x( 'Enter your country code here. See PayPal %s Documentation', 'placeholder: URL to PayPal Country Codes.', 'learndash' ),
'' . __( 'Country Codes', 'learndash' ) . ''
),
'value' => ( ( isset( $this->setting_option_values['paypal_country'] ) ) && ( ! empty( $this->setting_option_values['paypal_country'] ) ) ) ? $this->setting_option_values['paypal_country'] : 'US',
'class' => 'regular-text',
'validate_callback' => array( $this, 'validate_section_paypal_country' ),
),
'paypal_cancelurl' => array(
'name' => 'paypal_cancelurl',
'type' => 'text',
'label' => esc_html__( 'PayPal Cancel URL', 'learndash' ),
'help_text' => esc_html__( 'Enter the URL used for purchase cancellations.', 'learndash' ),
'value' => ( ( isset( $this->setting_option_values['paypal_cancelurl'] ) ) && ( ! empty( $this->setting_option_values['paypal_cancelurl'] ) ) ) ? $this->setting_option_values['paypal_cancelurl'] : get_home_url(),
'class' => 'regular-text',
),
'paypal_returnurl' => array(
'name' => 'paypal_returnurl',
'type' => 'text',
'label' => esc_html__( 'PayPal Return ', 'learndash' ),
'help_text' => esc_html__( 'Enter the URL used for completed purchases (typically a thank you page).', 'learndash' ),
'value' => ( ( isset( $this->setting_option_values['paypal_returnurl'] ) ) && ( ! empty( $this->setting_option_values['paypal_returnurl'] ) ) ) ? $this->setting_option_values['paypal_returnurl'] : get_home_url(),
'class' => 'regular-text',
),
'paypal_notifyurl' => array(
'name' => 'paypal_notifyurl',
'type' => 'text',
'label' => esc_html__( 'PayPal Notify URL', 'learndash' ),
'help_text' => esc_html__( 'Enter the URL used for IPN notifications.', 'learndash' ),
'value' => ( ( isset( $this->setting_option_values['paypal_notifyurl'] ) ) && ( ! empty( $this->setting_option_values['paypal_notifyurl'] ) ) ) ? $this->setting_option_values['paypal_notifyurl'] : $default_paypal_notifyurl,
'class' => 'regular-text',
),
'paypal_sandbox' => array(
'name' => 'paypal_sandbox',
'type' => 'checkbox',
'label' => esc_html__( 'Use PayPal Sandbox', 'learndash' ),
'help_text' => esc_html__( 'Check to enable the PayPal sandbox.', 'learndash' ),
'value' => isset( $this->setting_option_values['paypal_sandbox'] ) ? $this->setting_option_values['paypal_sandbox'] : 'no',
'options' => array(
'yes' => esc_html__( 'Yes', 'learndash' ),
),
),
);
$this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_section_key );
parent::load_settings_fields();
}
/**
* Validate PayPal Email.
*
* @param string $val to be validated.
* @param string $key Settings key.
* @param array $args Settings field args.
*
* @return string $val.
*/
public static function validate_section_paypal_email( $val, $key, $args = array() ) {
$val = trim( $val );
if ( ( ! empty( $val ) ) && ( ! is_email( $val ) ) ) {
add_settings_error( $args['setting_option_key'], $key, esc_html__( 'PayPal Email must be a valid email.', 'learndash' ), 'error' );
}
return $val;
}
/**
* Validate Settings Country field.
*
* @param string $val to be validated.
* @param string $key Settings key.
* @param array $args Settings field args.
*
* @return string $val.
*/
public static function validate_section_paypal_country( $val, $key, $args = array() ) {
if ( ( isset( $args['post_fields']['paypal_email'] ) ) && ( ! empty( $args['post_fields']['paypal_email'] ) ) ) {
$val = sanitize_text_field( $val );
if ( empty( $val ) ) {
add_settings_error( $args['setting_option_key'], $key, esc_html__( 'PayPal Country Code cannot be empty.', 'learndash' ), 'error' );
} elseif ( strlen( $val ) > 2 ) {
add_settings_error( $args['setting_option_key'], $key, esc_html__( 'PayPal Country Code should not be longer than 2 letters.', 'learndash' ), 'error' );
}
}
return $val;
}
/**
* Validate Settings Currency field.
*
* @param string $val to be validated.
* @param string $key Settings key.
* @param array $args Settings field args.
*
* @return string $val.
*/
public static function validate_section_paypal_currency( $val, $key, $args = array() ) {
if ( ( isset( $args['post_fields']['paypal_email'] ) ) && ( ! empty( $args['post_fields']['paypal_email'] ) ) ) {
$val = sanitize_text_field( $val );
if ( empty( $val ) ) {
add_settings_error( $args['setting_option_key'], $key, esc_html__( 'PayPal Currency Code cannot be empty.', 'learndash' ), 'error' );
} elseif ( strlen( $val ) > 3 ) {
add_settings_error( $args['setting_option_key'], $key, esc_html__( 'PayPal Currency Code should not be longer than 3 letters.', 'learndash' ), 'error' );
}
}
return $val;
}
}
}
add_action(
'learndash_settings_sections_init',
function() {
LearnDash_Settings_Section_PayPal::add_section_instance();
}
);
settings-sections/class-ld-settings-section-permalinks.php 0000666 00000026033 15214240575 0020124 0 ustar 00 Permalinks page..
*
* @package LearnDash
* @subpackage Settings
*/
if ( ( class_exists( 'LearnDash_Settings_Section' ) ) && ( ! class_exists( 'LearnDash_Settings_Section_Permalinks' ) ) ) {
/**
* Class to create the settings section.
*/
class LearnDash_Settings_Section_Permalinks extends LearnDash_Settings_Section {
/**
* Protected constructor for class
*/
protected function __construct() {
$this->settings_page_id = 'permalink';
// This is the 'option_name' key used in the wp_options table.
$this->setting_option_key = 'learndash_settings_permalinks';
// This is the HTML form field prefix used.
$this->setting_field_prefix = 'learndash_settings_permalinks';
// Used within the Settings API to uniquely identify this section.
$this->settings_section_key = 'learndash_settings_permalinks';
// Section label/header.
$this->settings_section_label = __( 'LearnDash Permalinks', 'learndash' );
// Used to show the section description above the fields. Can be empty.
$this->settings_section_description = __( 'Controls the URL slugs for the custom posts used by LearnDash.', 'learndash' );
add_action( 'admin_init', array( $this, 'admin_init' ) );
parent::__construct();
$this->save_settings_fields();
}
/**
* Hook into the admin init action to fire up the LD settings page init processing.
* Remember the Permalinks page is not a LD page.
*/
public function admin_init() {
do_action( 'learndash_settings_page_init', $this->settings_page_id );
}
/**
* Function to handle metabox init.
*
* @param string $settings_screen_id Screen ID of current page.
*/
public function add_meta_boxes( $settings_screen_id = '' ) {
global $wp_rewrite;
if ( $wp_rewrite->using_permalinks() ) {
add_meta_box(
$this->metabox_key,
$this->settings_section_label,
array( $this, 'show_meta_box' ),
$this->settings_screen_id,
$this->metabox_context,
$this->metabox_priority
);
}
}
/**
* Initialize the metabox settings values.
*/
public function load_settings_values() {
parent::load_settings_values();
if ( false === $this->setting_option_values ) {
$this->setting_option_values = array();
// On the initial if we don't have saved values we grab them from the Custom Labels.
$custom_label_settings = get_option( 'learndash_custom_label_settings', array() );
if ( ( isset( $custom_label_settings['courses'] ) ) && ( ! empty( $custom_label_settings['courses'] ) ) ) {
$this->setting_option_values['courses'] = learndash_get_custom_label_slug( 'courses' );
}
if ( ( isset( $custom_label_settings['lessons'] ) ) && ( ! empty( $custom_label_settings['lessons'] ) ) ) {
$this->setting_option_values['lessons'] = learndash_get_custom_label_slug( 'lessons' );
}
if ( ( isset( $custom_label_settings['topic'] ) ) && ( ! empty( $custom_label_settings['topic'] ) ) ) {
$this->setting_option_values['topics'] = learndash_get_custom_label_slug( 'topic' );
}
if ( ( isset( $custom_label_settings['quizzes'] ) ) && ( ! empty( $custom_label_settings['quizzes'] ) ) ) {
$this->setting_option_values['quizzes'] = learndash_get_custom_label_slug( 'quizzes' );
}
// As we don't have existing values we want to save here and force the flush rewrite.
update_option( $this->settings_section_key, $this->setting_option_values );
learndash_setup_rewrite_flush();
}
$this->setting_option_values = wp_parse_args(
$this->setting_option_values,
array(
'courses' => 'courses',
'lessons' => 'lessons',
'topics' => 'topic',
'quizzes' => 'quizzes',
)
);
}
/**
* Initialize the metabox settings fields.
*/
public function load_settings_fields() {
global $wp_rewrite;
if ( $wp_rewrite->using_permalinks() ) {
$this->setting_option_fields = array(
'courses' => array(
'name' => 'courses',
'type' => 'text',
'label' => sprintf(
// translators: placeholder: Courses.
esc_html_x( '%s', 'placeholder: Courses', 'learndash' ),
LearnDash_Custom_Label::get_label( 'courses' )
),
'value' => $this->setting_option_values['courses'],
'class' => 'regular-text',
),
'lessons' => array(
'name' => 'lessons',
'type' => 'text',
'label' => sprintf(
// translators: placeholder: Lessons.
esc_html_x( '%s', 'placeholder: Lessons', 'learndash' ),
LearnDash_Custom_Label::get_label( 'lessons' )
),
'value' => $this->setting_option_values['lessons'],
'class' => 'regular-text',
),
'topics' => array(
'name' => 'topics',
'type' => 'text',
'label' => sprintf(
// translators: placeholder: Topics.
esc_html_x( '%s', 'placeholder: Topics', 'learndash' ),
LearnDash_Custom_Label::get_label( 'topics' )
),
'value' => $this->setting_option_values['topics'],
'class' => 'regular-text',
),
'quizzes' => array(
'name' => 'quizzes',
'type' => 'text',
'label' => sprintf(
// translators: placeholder: Quizzes.
esc_html_x( '%s', 'placeholder: Quizzes', 'learndash' ),
LearnDash_Custom_Label::get_label( 'quizzes' )
),
'value' => $this->setting_option_values['quizzes'],
'class' => 'regular-text',
)
);
}
if ( $wp_rewrite->using_permalinks() ) {
$example_regular_topic_url = get_option( 'home' ) . '/' . $this->setting_option_values['topics'] . '/topic-slug';
$example_nested_topic_url = get_option( 'home' ) . '/' . $this->setting_option_values['courses'] . '/course-slug/' . $this->setting_option_values['lessons'] . '/lesson-slug/' . $this->setting_option_values['topics'] . '/topic-slug';
} else {
$example_regular_topic_url = add_query_arg( learndash_get_post_type_slug( 'topic' ), 'topic-slug', get_option( 'home' ) );
$example_nested_topic_url = get_option( 'home' );
$example_nested_topic_url = add_query_arg( learndash_get_post_type_slug( 'course'), 'course-slug', $example_nested_topic_url );
$example_nested_topic_url = add_query_arg( learndash_get_post_type_slug( 'lesson' ), 'lesson-slug', $example_nested_topic_url );
$example_nested_topic_url = add_query_arg( learndash_get_post_type_slug( 'topic' ), 'topic-slug', $example_nested_topic_url );
}
$this->setting_option_fields['nested_urls'] = array(
'name' => 'nested_urls',
'type' => 'checkbox',
'label' => __( 'Enable Nested URLs', 'learndash' ),
'desc' => sprintf(
// translators: placeholders: Lesson, Topic, Quiz, Course, Site Home URL, URL to Course Builder Settings.
_x(
'This option will restructure %1$s, %2$s and %3$s URLs so they are nested hierarchically within the %4$s URL.%5$s the nested URL would be %6$s. If Course Builder Share Steps has been enabled this setting is also automatically enabled.',
'placeholders: Lesson, Topic, Quiz, Course, Site Home URL, URL to Course Builder Settings',
'learndash'
),
LearnDash_Custom_Label::get_label( 'lesson' ),
LearnDash_Custom_Label::get_label( 'topic' ),
LearnDash_Custom_Label::get_label( 'quiz' ),
LearnDash_Custom_Label::get_label( 'course' ),
$example_regular_topic_url,
$example_nested_topic_url,
admin_url( 'admin.php?page=courses-options' )
),
'value' => isset( $this->setting_option_values['nested_urls'] ) ? $this->setting_option_values['nested_urls'] : '',
'options' => array(
'yes' => __( 'Yes', 'learndash' ),
),
);
$this->setting_option_fields['nonce'] = array(
'name' => 'nonce',
'type' => 'hidden',
'label' => '',
'value' => wp_create_nonce( 'learndash_permalinks_nonce' ),
'class' => 'hidden',
);
$this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_section_key );
parent::load_settings_fields();
}
/**
* Save the metabox fields. This is needed due to special processing needs.
*/
public function save_settings_fields() {
if ( isset( $_POST[ $this->setting_field_prefix ] ) ) {
if ( ( isset( $_POST[ $this->setting_field_prefix ]['nonce'] ) ) && ( wp_verify_nonce( $_POST[ $this->setting_field_prefix ]['nonce'], 'learndash_permalinks_nonce' ) ) ) {
$post_fields = $_POST[ $this->setting_field_prefix ];
if ( ( isset( $post_fields['courses'] ) ) && ( ! empty( $post_fields['courses'] ) ) ) {
$this->setting_option_values['courses'] = $this->esc_url( $post_fields['courses'] );
learndash_setup_rewrite_flush();
}
if ( ( isset( $post_fields['lessons'] ) ) && ( ! empty( $post_fields['lessons'] ) ) ) {
$this->setting_option_values['lessons'] = $this->esc_url( $post_fields['lessons'] );
learndash_setup_rewrite_flush();
}
if ( ( isset( $post_fields['topics'] ) ) && ( ! empty( $post_fields['topics'] ) ) ) {
$this->setting_option_values['topics'] = $this->esc_url( $post_fields['topics'] );
learndash_setup_rewrite_flush();
}
if ( ( isset( $post_fields['quizzes'] ) ) && ( ! empty( $post_fields['quizzes'] ) ) ) {
$this->setting_option_values['quizzes'] = $this->esc_url( $post_fields['quizzes'] );
learndash_setup_rewrite_flush();
}
if ( ( isset( $post_fields['nested_urls'] ) ) && ( ! empty( $post_fields['nested_urls'] ) ) ) {
$this->setting_option_values['nested_urls'] = $this->esc_url( $post_fields['nested_urls'] );
learndash_setup_rewrite_flush();
} else {
// We check the Course Options > Course Builder setting. If this is set to 'yes' then we MUST keep the nested URLs set to true.
if ( ! isset( $this->setting_option_values['nested_urls'] ) ) {
$this->setting_option_values['nested_urls'] = 'no';
}
if ( 'yes' !== $this->setting_option_values['nested_urls'] ) {
$learndash_settings_courses_builder = get_option( 'learndash_settings_courses_management_display', array() );
if ( ! isset( $learndash_settings_courses_builder['course_builder_shared_steps'] ) ) {
$learndash_settings_courses_builder['course_builder_shared_steps'] = 'no';
}
if ( 'yes' === $learndash_settings_courses_builder['course_builder_shared_steps'] ) {
$this->setting_option_values['nested_urls'] = 'yes';
learndash_setup_rewrite_flush();
}
}
}
update_option( $this->settings_section_key, $this->setting_option_values );
}
}
}
/**
* Class utility function to escape the URL
*
* @param string $value URL to Escape.
*
* @return string filtered URL.
*/
public function esc_url( $value = '' ) {
if ( ! empty( $value ) ) {
$value = esc_url_raw( trim( $value ) );
$value = str_replace( 'http://', '', $value );
return untrailingslashit( $value );
}
}
}
}
add_action(
'learndash_settings_sections_init',
function() {
LearnDash_Settings_Section_Permalinks::add_section_instance();
}
);
settings-sections/class-ld-settings-section-lessons-cpt.php 0000666 00000020666 15214240575 0020237 0 ustar 00 settings_screen_id = 'sfwd-lessons_page_lessons-options';
// The page ID (different than the screen ID).
$this->settings_page_id = 'lessons-options';
// This is the 'option_name' key used in the wp_options table.
$this->setting_option_key = 'learndash_settings_lessons_cpt';
// This is the HTML form field prefix used.
$this->setting_field_prefix = 'learndash_settings_lessons_cpt';
// Used within the Settings API to uniquely identify this section.
$this->settings_section_key = 'cpt_options';
// Section label/header.
$this->settings_section_label = sprintf(
// translators: placeholder: Lesson.
esc_html_x( '%s Custom Post Type Options', 'placeholder: Lesson', 'learndash' ),
learndash_get_custom_label( 'lesson' )
);
// Used to show the section description above the fields. Can be empty.
$this->settings_section_description = sprintf(
// translators: placeholder: Lessons.
esc_html_x( 'Control options specific to the %s post type', 'placeholder: Lessons', 'learndash' ),
learndash_get_custom_label( 'lessons' )
);
parent::__construct();
}
/**
* Initialize the metabox settings values.
*/
public function load_settings_values() {
parent::load_settings_values();
if ( ( false === $this->setting_option_values ) || ( '' === $this->setting_option_values ) ) {
if ( '' === $this->setting_option_values ) {
$this->setting_option_values = array();
}
$this->setting_option_values = array(
'include_in_search' => 'yes',
'has_archive' => 'yes',
'has_feed' => '',
'supports' => array( 'thumbnail', 'revisions' ),
);
}
if ( ! isset( $this->setting_option_values['include_in_search'] ) ) {
if ( ( isset( $this->setting_option_values['exclude_from_search'] ) ) && ( 'yes' === $this->setting_option_values['exclude_from_search'] ) ) {
$this->setting_option_values['include_in_search'] = '';
} else {
$this->setting_option_values['include_in_search'] = 'yes';
}
}
if ( ! isset( $this->setting_option_values['has_archive'] ) ) {
$this->setting_option_values['has_archive'] = 'yes';
}
if ( ! isset( $this->setting_option_values['has_feed'] ) ) {
$this->setting_option_values['has_feed'] = '';
}
if ( ! isset( $this->setting_option_values['supports'] ) ) {
$this->setting_option_values['supports'] = array( 'thumbnail', 'revisions' );
}
}
/**
* Initialize the metabox settings fields.
*/
public function load_settings_fields() {
$cpt_archive_url = home_url( LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Section_Permalinks', 'lessons' ) );
$cpt_rss_url = add_query_arg( 'post_type', 'sfwd-lessons', get_post_type_archive_feed_link( 'post' ) );
$this->setting_option_fields = array(
'include_in_search' => array(
'name' => 'include_in_search',
'type' => 'checkbox-switch',
'label' => sprintf(
// translators: placeholder: Lesson.
esc_html_x( '%s Search', 'placeholder: Lesson', 'learndash' ),
learndash_get_custom_label( 'lesson' )
),
'help_text' => sprintf(
// translators: placeholder: lesson.
esc_html_x( 'Includes the %s post type in front end search results', 'placeholder: lesson', 'learndash' ),
learndash_get_custom_label_lower( 'lesson' )
),
'value' => $this->setting_option_values['include_in_search'],
'options' => array(
'yes' => '',
),
),
'has_archive' => array(
'name' => 'has_archive',
'type' => 'checkbox-switch',
'label' => esc_html__( 'Archive Page', 'learndash' ),
'help_text' => sprintf(
// translators: placeholder: lessons, link to WP Permalins page.
esc_html_x( 'Enables the front end archive page where all %1$s are listed. You must %2$s for the change to take effect.', 'placeholder: , link to WP Permalins page', 'learndash' ),
learndash_get_custom_label_lower( 'lessons' ),
'' . esc_html__( 're-save your permalinks', 'learndash' ) . ''
),
'value' => $this->setting_option_values['has_archive'],
'options' => array(
'' => '',
'yes' => sprintf(
// translators: placeholder: URL for CPT Archive.
esc_html_x( 'Archive URL: %s', 'placeholder: URL for CPT Archive', 'learndash' ),
'' . $cpt_archive_url . ''
),
),
'child_section_state' => ( 'yes' === $this->setting_option_values['has_archive'] ) ? 'open' : 'closed',
),
'has_feed' => array(
'name' => 'has_feed',
'type' => 'checkbox-switch',
'label' => esc_html__( 'RSS/Atom Feed', 'learndash' ),
'help_text' => sprintf(
// translators: placeholder: lesson
esc_html_x( 'Enables an RSS feed for all %1$s posts.', 'placeholder: lesson', 'learndash' ),
learndash_get_custom_label_lower( 'lesson' )
),
'value' => $this->setting_option_values['has_feed'],
'options' => array(
'' => '',
'yes' => sprintf(
// translators: placeholder: URL for CPT Archive.
esc_html_x( 'RSS Feed URL: %s', 'placeholder: URL for RSS Feed', 'learndash' ),
'' . $cpt_rss_url . ''
),
),
'parent_setting' => 'has_archive',
),
'supports' => array(
'name' => 'supports',
'type' => 'checkbox',
'label' => esc_html__( 'Editor Supported Settings', 'learndash' ),
'help_text' => esc_html__( 'Enables WordPress supported settings within the editor and theme.', 'learndash' ),
'value' => $this->setting_option_values['supports'],
'options' => array(
'thumbnail' => esc_html__( 'Featured image', 'learndash' ),
'comments' => esc_html__( 'Comments', 'learndash' ),
'custom-fields' => esc_html__( 'Custom Fields', 'learndash' ),
'revisions' => esc_html__( 'Revisions', 'learndash' ),
),
),
);
$this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_section_key );
parent::load_settings_fields();
}
/**
* Intercept the WP options save logic and check that we have a valid nonce.
*
* @since 3.0
* @param array $value Array of section fields values.
* @param array $old_value Array of old values.
* @param string $section_key Section option key should match $this->setting_option_key.
*/
public function section_pre_update_option( $new_values = '', $old_values = '', $setting_option_key = '' ) {
if ( $setting_option_key === $this->setting_option_key ) {
$new_values = parent::section_pre_update_option( $new_values, $old_values, $setting_option_key );
if ( ! isset( $new_values['include_in_search'] ) ) {
$new_values['include_in_search'] = '';
}
if ( ! isset( $new_values['has_archive'] ) ) {
$new_values['has_archive'] = '';
$new_values['has_feed'] = '';
}
if ( ! isset( $new_values['has_feed'] ) ) {
$new_values['has_feed'] = '';
}
if ( ! isset( $new_values['supports'] ) ) {
$new_values['supports'] = array();
}
if ( $new_values !== $old_values ) {
if ( ( ! isset( $old_values['has_archive'] ) ) || ( $new_values['has_archive'] !== $old_values['has_archive'] ) ) {
learndash_setup_rewrite_flush();
}
//if ( in_array( 'comments', $new_values['supports'] ) ) {
// learndash_update_posts_comment_status( 'sfwd-lessons', 'open' );
//} else {
// learndash_update_posts_comment_status( 'sfwd-lessons', 'closed' );
//}
}
}
return $new_values;
}
// End of functions.
}
}
add_action(
'learndash_settings_sections_init',
function() {
LearnDash_Settings_Lessons_CPT::add_section_instance();
}
);
settings-sections/class-ld-settings-section-side-submit.php 0000666 00000003772 15214240575 0020211 0 ustar 00 settings_screen_id = $args['settings_screen_id'];
}
if ( ( isset( $args['settings_page_id'] ) ) && ( ! empty( $args['settings_page_id'] ) ) ) {
$this->settings_page_id = $args['settings_page_id'];
}
if ( ( ! empty( $this->settings_screen_id ) ) && ( ! empty( $this->settings_page_id ) ) ) {
// This is the 'option_name' key used in the wp_options table.
$this->setting_option_key = 'submitdiv';
// Section label/header.
$this->settings_section_label = esc_html__( 'Save Options', 'learndash' );
$this->metabox_context = 'side';
$this->metabox_priority = 'high';
parent::__construct();
// We override the parent value set for $this->metabox_key because we want the div ID to match the details WordPress
// value so it will be hidden.
$this->metabox_key = 'submitdiv';
}
}
/**
* Primary function to show the metabox output
*/
public function show_meta_box() {
?>
settings_screen_id = 'sfwd-courses'; // Used within the Settings API to uniquely identify this section. $this->settings_metabox_key = 'learndash-course-access-settings'; // Section label/header. $this->settings_section_label = sprintf( // translators: placeholder: Course. esc_html_x( '%s Access Settings', 'placeholder: Course', 'learndash' ), learndash_get_custom_label( 'course' ) ); $this->settings_section_description = sprintf( // translators: placeholder: course. esc_html_x( 'Controls how users will gain access to the %s', 'placeholder: course', 'learndash' ), learndash_get_custom_label_lower( 'course' ) ); add_filter( 'learndash_metabox_save_fields_' . $this->settings_metabox_key, array( $this, 'filter_saved_fields' ), 30, 3 ); add_filter( 'learndash_admin_settings_data', array( $this, 'learndash_admin_settings_data' ), 30, 1 ); // Map internal settings field ID to legacy field ID. $this->settings_fields_map = array( // New fields 'course_access_list_enabled' => 'course_access_list_enabled', // Legacy fields 'course_price_type' => 'course_price_type', 'course_price_type_paynow_price' => 'course_price', 'course_price_type_subscribe_price' => 'course_price', 'course_price_type_subscribe_billing_cycle' => 'course_price_billing_cycle', 'course_price_type_closed_custom_button_label' => 'custom_button_label', 'course_price_type_closed_custom_button_url' => 'custom_button_url', 'course_price_type_closed_price' => 'course_price', 'course_prerequisite_enabled' => 'course_prerequisite_enabled', 'course_prerequisite' => 'course_prerequisite', 'course_prerequisite_compare' => 'course_prerequisite_compare', 'course_points_enabled' => 'course_points_enabled', 'course_points' => 'course_points', 'course_points_access' => 'course_points_access', 'expire_access' => 'expire_access', 'expire_access_days' => 'expire_access_days', 'expire_access_delete_progress' => 'expire_access_delete_progress', 'course_disable_lesson_progression' => 'course_disable_lesson_progression', 'course_access_list' => 'course_access_list', ); parent::__construct(); } /** * Add script data to array. * * @since 3.0 * @param array $script_data Script data array to be sent out to browser. * @return array $script_data */ public function learndash_admin_settings_data( $script_data = array() ) { $script_data['valid_recurring_paypal_day_range'] = esc_html__( 'Valid range is 1 to 90 when the Billing Cycle is set to days.', 'learndash' ); $script_data['valid_recurring_paypal_week_range'] = esc_html__( 'Valid range is 1 to 52 when the Billing Cycle is set to weeks.', 'learndash' ); $script_data['valid_recurring_paypal_month_range'] = esc_html__( 'Valid range is 1 to 24 when the Billing Cycle is set to months.', 'learndash' ); $script_data['valid_recurring_paypal_year_range'] = esc_html__( 'Valid range is 1 to 5 when the Billing Cycle is set to years.', 'learndash' ); return $script_data; } /** * Initialize the metabox settings values. */ public function load_settings_values() { parent::load_settings_values(); if ( true === $this->settings_values_loaded ) { if ( ! isset( $this->setting_option_values['course_points_enabled'] ) ) { $this->setting_option_values['course_points_enabled'] = ''; } if ( ! isset( $this->setting_option_values['expire_access'] ) ) { $this->setting_option_values['expire_access'] = ''; } if ( ! isset( $this->setting_option_values['expire_access_delete_progress'] ) ) { $this->setting_option_values['expire_access_delete_progress'] = ''; } if ( ! isset( $this->setting_option_values['course_access_list_enabled'] ) ) { $this->setting_option_values['course_access_list_enabled'] = ''; } if ( ! isset( $this->setting_option_values['course_price_type_paynow_price'] ) ) { $this->setting_option_values['course_price_type_paynow_price'] = ''; } if ( ! isset( $this->setting_option_values['course_price_type_subscribe_price'] ) ) { $this->setting_option_values['course_price_type_subscribe_price'] = ''; } if ( ! isset( $this->setting_option_values['course_price_type_closed_price'] ) ) { $this->setting_option_values['course_price_type_closed_price'] = ''; } if ( ! isset( $this->setting_option_values['course_price_type_closed_custom_button_url'] ) ) { $this->setting_option_values['course_price_type_closed_custom_button_url'] = ''; } if ( ! isset( $this->setting_option_values['course_price_type'] ) ) { $this->setting_option_values['course_price_type'] = 'open'; } if ( ! isset( $this->setting_option_values['course_prerequisite_enabled'] ) ) { $this->setting_option_values['course_prerequisite_enabled'] = ''; } if ( ! isset( $this->setting_option_values['course_prerequisite'] ) ) { $this->setting_option_values['course_prerequisite'] = ''; } if ( ! isset( $this->setting_option_values['course_prerequisite_compare'] ) ) { $this->setting_option_values['course_prerequisite_compare'] = 'ANY'; } if ( ! isset( $this->setting_option_values['course_points_access'] ) ) { $this->setting_option_values['course_points_access'] = ''; } if ( ! isset( $this->setting_option_values['course_points'] ) ) { $this->setting_option_values['course_points'] = ''; } if ( ! isset( $this->setting_option_values['expire_access_days'] ) ) { $this->setting_option_values['expire_access_days'] = ''; } if ( ! isset( $this->setting_option_values['course_access_list'] ) ) { $this->setting_option_values['course_access_list'] = ''; } if ( ! isset( $this->setting_option_values['course_price_type_closed_custom_button_label'] ) ) { $this->setting_option_values['course_price_type_closed_custom_button_label'] = ''; } } } /** * Initialize the metabox settings fields. */ public function load_settings_fields() { global $sfwd_lms; $this->settings_sub_option_fields = array(); $select_course_options = $sfwd_lms->select_a_course(); if ( ( defined( 'LEARNDASH_SELECT2_LIB' ) ) && ( true === apply_filters( 'learndash_select2_lib', LEARNDASH_SELECT2_LIB ) ) ) { $select_course_options_default = sprintf( // translators: placeholder: course. esc_html_x( 'Search or select a %s…', 'placeholder: course', 'learndash' ), learndash_get_custom_label( 'course' ) ); } else { $select_course_options_default = array( '' => sprintf( // translators: placeholder: course. esc_html_x( 'Select %s', 'placeholder: course', 'learndash' ), learndash_get_custom_label( 'course' ) ), ); if ( ( is_array( $select_course_options ) ) && ( ! empty( $select_course_options ) ) ) { $select_course_options = $select_course_options_default + $select_course_options; } else { $select_course_options = $select_course_options_default; } $select_course_options_default = ''; } $this->setting_option_fields = array( 'course_price_type_paynow_price' => array( 'name' => 'course_price_type_paynow_price', 'label' => sprintf( // translators: placeholder: Course. esc_html_x( '%s Price', 'placeholder: Course', 'learndash' ), learndash_get_custom_label( 'course' ) ), 'type' => 'text', 'class' => '-medium', 'value' => $this->setting_option_values['course_price_type_paynow_price'], 'default' => '', ), ); parent::load_settings_fields(); $this->settings_sub_option_fields['course_price_type_paynow_fields'] = $this->setting_option_fields; $this->setting_option_fields = array( 'course_price_type_subscribe_price' => array( 'name' => 'course_price_type_subscribe_price', 'label' => sprintf( // translators: placeholder: Course. esc_html_x( '%s Price', 'placeholder: Course', 'learndash' ), learndash_get_custom_label( 'course' ) ), 'type' => 'text', 'class' => '-medium', 'value' => $this->setting_option_values['course_price_type_subscribe_price'], 'default' => '', ), 'course_price_type_subscribe_billing_cycle' => array( 'name' => 'course_price_type_subscribe_billing_cycle', 'label' => esc_html__( 'Billing Cycle', 'learndash' ), 'type' => 'custom', 'html' => $sfwd_lms->learndash_course_price_billing_cycle_html(), ), ); parent::load_settings_fields(); $this->settings_sub_option_fields['course_price_type_subscribe_fields'] = $this->setting_option_fields; $this->setting_option_fields = array( /* 'course_price_type_closed_custom_button_label' => array( 'name' => 'course_price_type_closed_custom_button_label', 'label' => esc_html__( 'Label (optional)', 'learndash' ), 'type' => 'text', 'placeholder' => learndash_get_custom_label( 'button_take_this_course' ), 'value' => $this->setting_option_values['course_price_type_closed_custom_button_label'], 'help_text' => esc_html__( 'Label displayed in the Course Grid listing. Requires Course Grid add-on.', 'learndash'), 'default' => '', ), */ 'course_price_type_closed_price' => array( 'name' => 'course_price_type_closed_price', 'label' => sprintf( // translators: placeholder: Course. esc_html_x( '%s Price', 'placeholder: Course', 'learndash' ), learndash_get_custom_label( 'course' ) ), 'type' => 'text', 'class' => '-medium', 'value' => $this->setting_option_values['course_price_type_closed_price'], 'default' => '', ), 'course_price_type_closed_custom_button_url' => array( 'name' => 'course_price_type_closed_custom_button_url', 'label' => esc_html__( 'Button URL', 'learndash' ), 'type' => 'url', 'class' => 'full-text', 'value' => $this->setting_option_values['course_price_type_closed_custom_button_url'], 'help_text' => sprintf( // translators: placeholder: "Take this Course" button label esc_html_x( 'Redirect the "%s" button to a specific URL.', 'placeholder: "Take this Course" button label', 'learndash' ), learndash_get_custom_label( 'button_take_this_course' ) ), 'default' => '', ), ); /* if ( ! defined( 'LEARNDASH_COURSE_GRID_VERSION' ) ) { unset( $this->setting_option_fields['course_price_type_closed_custom_button_label'] ); } */ parent::load_settings_fields(); $this->settings_sub_option_fields['course_price_type_closed_fields'] = $this->setting_option_fields; $this->setting_option_fields = array( 'course_price_type' => array( 'name' => 'course_price_type', 'label' => esc_html__( 'Access Mode', 'learndash' ), 'type' => 'radio', 'value' => $this->setting_option_values['course_price_type'], 'default' => 'open', 'options' => array( 'open' => array( 'label' => esc_html__( 'Open', 'learndash' ), 'description' => sprintf( // translators: placeholder: course. esc_html_x( 'The %s is not protected. Any user can access its content without the need to be logged-in or enrolled.', 'placeholder: course', 'learndash' ), learndash_get_custom_label_lower( 'course' ) ), ), 'free' => array( 'label' => esc_html__( 'Free', 'learndash' ), 'description' => sprintf( // translators: placeholder: course. esc_html_x( 'The %s is protected. Registration and enrollment are required in order to access the content.', 'placeholder: course', 'learndash' ), learndash_get_custom_label_lower( 'course' ) ), ), 'paynow' => array( 'label' => esc_html__( 'Buy now', 'learndash' ), 'description' => sprintf( // translators: placeholder: course, course. esc_html_x( 'The %1$s is protected via the LearnDash built-in PayPal and/or Stripe. Users need to purchase the %2$s (one-time fee) in order to gain access.', 'placeholder: course, course', 'learndash' ), learndash_get_custom_label_lower( 'course' ), learndash_get_custom_label_lower( 'course' ) ), 'inline_fields' => array( 'course_price_type_paynow' => $this->settings_sub_option_fields['course_price_type_paynow_fields'], ), 'inner_section_state' => ( 'paynow' === $this->setting_option_values['course_price_type'] ) ? 'open' : 'closed', ), 'subscribe' => array( 'label' => esc_html__( 'Recurring', 'learndash' ), 'description' => sprintf( // translators: placeholder: course, course. esc_html_x( 'The %1$s is protected via the LearnDash built-in PayPal and/or Stripe. Users need to purchase the %2$s (recurring fee) in order to gain access.', 'placeholder: course, course', 'learndash' ), learndash_get_custom_label_lower( 'course' ), learndash_get_custom_label_lower( 'course' ) ), 'inline_fields' => array( 'course_price_type_subscribe' => $this->settings_sub_option_fields['course_price_type_subscribe_fields'], ), 'inner_section_state' => ( 'subscribe' === $this->setting_option_values['course_price_type'] ) ? 'open' : 'closed', ), 'closed' => array( 'label' => esc_html__( 'Closed', 'learndash' ), 'description' => sprintf( // translators: placeholder: course. esc_html_x( 'The %s can only be accessed through admin enrollment (manual), group enrollment, or integration (shopping cart or membership) enrollment. No enrollment button will be displayed, unless a URL is set (optional).', 'placeholder: course', 'learndash' ), learndash_get_custom_label_lower( 'course' ) ), 'inline_fields' => array( 'course_price_type_closed' => $this->settings_sub_option_fields['course_price_type_closed_fields'], ), 'inner_section_state' => ( 'closed' === $this->setting_option_values['course_price_type'] ) ? 'open' : 'closed', ), ), ), 'course_prerequisite_enabled' => array( 'name' => 'course_prerequisite_enabled', 'label' => sprintf( // translators: placeholder: Course. esc_html_x( '%s Prerequisites', 'placeholder: Course', 'learndash' ), learndash_get_custom_label( 'course' ) ), 'type' => 'checkbox-switch', 'value' => $this->setting_option_values['course_prerequisite_enabled'], 'default' => '', 'options' => array( 'on' => '', ), 'child_section_state' => ( 'on' === $this->setting_option_values['course_prerequisite_enabled'] ) ? 'open' : 'closed', ), 'course_prerequisite_compare' => array( 'name' => 'course_prerequisite_compare', 'label' => esc_html__( 'Compare Mode', 'learndash' ), 'type' => 'radio', 'default' => 'ANY', 'value' => $this->setting_option_values['course_prerequisite_compare'], 'options' => array( 'ANY' => array( 'label' => esc_html__( 'Any Selected', 'learndash' ), 'description' => sprintf( // translators: placeholder: courses, course. esc_html_x( 'The user must complete any one of the selected %1$s in order to access this %2$s', 'placeholder: course, course', 'learndash' ), learndash_get_custom_label_lower( 'courses' ), learndash_get_custom_label_lower( 'course' ) ), ), 'ALL' => array( 'label' => esc_html__( 'All Selected', 'learndash' ), 'description' => sprintf( // translators: placeholder: course, course. esc_html_x( 'The user must complete all selected %1$s in order to access this %2$s', 'placeholder: course, course', 'learndash' ), learndash_get_custom_label_lower( 'course' ), learndash_get_custom_label_lower( 'course' ) ), ), ), 'parent_setting' => 'course_prerequisite_enabled', ), 'course_prerequisite' => array( 'name' => 'course_prerequisite', 'type' => 'multiselect', 'multiple' => 'true', 'default' => '', 'value' => $this->setting_option_values['course_prerequisite'], 'placeholder' => $select_course_options_default, 'value_type' => 'intval', 'label' => sprintf( // translators: placeholder: Courses. esc_html_x( '%s to Complete', 'placeholder: courses', 'learndash' ), learndash_get_custom_label( 'courses' ) ), 'parent_setting' => 'course_prerequisite_enabled', 'options' => $select_course_options, ), 'course_points_enabled' => array( 'name' => 'course_points_enabled', 'label' => sprintf( // translators: placeholder: Course esc_html_x( '%s Points', 'placeholder: Course', 'learndash' ), learndash_get_custom_label( 'course' ) ), 'type' => 'checkbox-switch', 'value' => $this->setting_option_values['course_points_enabled'], 'options' => array( 'on' => '', ), 'child_section_state' => ( 'on' === $this->setting_option_values['course_points_enabled'] ) ? 'open' : 'closed', ), 'course_points_access' => array( 'name' => 'course_points_access', 'label' => esc_html__( 'Required for Access', 'learndash' ), 'type' => 'number', 'value' => $this->setting_option_values['course_points_access'], 'default' => 0, 'class' => 'small-text', 'input_label' => esc_html__( 'point(s)', 'learndash' ), 'input_error' => esc_html__( 'Value should be zero or greater with up to 2 decimal places.', 'learndash' ), 'parent_setting' => 'course_points_enabled', 'attrs' => array( 'step' => 'any', 'min' => '0.00', //'max' => '10.00', 'can_decimal' => 2, 'can_empty' => true, ), 'help_text' => sprintf( // translators: placeholder: course. esc_html_x( 'Number of points required in order to gain access to this %s.', 'placeholder: course.', 'learndash' ), learndash_get_custom_label_lower( 'course' ) ), ), 'course_points' => array( 'name' => 'course_points', 'label' => esc_html__( 'Awarded on Completion', 'learndash' ), 'type' => 'number', 'step' => 'any', 'min' => '0', 'value' => $this->setting_option_values['course_points'], 'default' => '', 'class' => 'small-text', 'input_label' => esc_html__( 'point(s)', 'learndash' ), 'parent_setting' => 'course_points_enabled', 'help_text' => sprintf( // translators: placeholder: course. esc_html_x( 'Number of points awarded for completing this %s.', 'placeholder: course.', 'learndash' ), learndash_get_custom_label_lower( 'course' ) ), 'input_error' => esc_html__( 'Value should be zero or greater with up to 2 decimal places.', 'learndash' ), 'attrs' => array( 'step' => 'any', 'min' => '0.00', //'max' => '10.00', 'can_decimal' => 2, 'can_empty' => true, ), ), 'expire_access' => array( 'name' => 'expire_access', 'label' => sprintf( // translators: placeholder: Course. esc_html_x( '%s Access Expiration', 'placeholder: Course', 'learndash' ), learndash_get_custom_label( 'course' ) ), 'type' => 'checkbox-switch', 'options' => array( 'on' => '', ), 'value' => $this->setting_option_values['expire_access'], 'child_section_state' => ( 'on' === $this->setting_option_values['expire_access'] ) ? 'open' : 'closed', ), 'expire_access_days' => array( 'name' => 'expire_access_days', 'label' => esc_html__( 'Access Period', 'learndash' ), 'type' => 'number', 'class' => 'small-text', 'min' => '0', 'value' => $this->setting_option_values['expire_access_days'], 'input_label' => esc_html__( 'days', 'learndash' ), 'parent_setting' => 'expire_access', 'help_text' => sprintf( // translators: placeholder: course. esc_html_x( 'Set the number of days a user will have access to the %s from enrollment date.', 'placeholder: course.', 'learndash' ), learndash_get_custom_label_lower( 'course' ) ), ), 'expire_access_delete_progress' => array( 'name' => 'expire_access_delete_progress', 'label' => esc_html__( 'Data Deletion', 'learndash' ), 'type' => 'checkbox-switch', 'options' => array( 'on' => sprintf( // translators: placeholder: course. esc_html_x( 'All user %s data will be deleted upon access expiration', 'placeholder: course.', 'learndash' ), learndash_get_custom_label_lower( 'course' ) ), '' => '', ), 'value' => $this->setting_option_values['expire_access_delete_progress'], 'parent_setting' => 'expire_access', 'help_text' => sprintf( // translators: placeholder: course. esc_html_x( 'Delete the user\'s %1$s and %2$s data when the %3$s access expires.', 'placeholder: course, quiz, course.', 'learndash' ), learndash_get_custom_label_lower( 'course' ), learndash_get_custom_label_lower( 'quiz' ), learndash_get_custom_label_lower( 'course' ) ), ), 'course_access_list_enabled' => array( 'name' => 'course_access_list_enabled', 'label' => sprintf( // translators: placeholder: Course esc_html_x( 'Alter %s Access List', 'placeholder: Course', 'learndash' ), learndash_get_custom_label( 'course' ) ), 'type' => 'checkbox-switch', 'options' => array( 'on' => sprintf( // translators: placeholder: Course esc_html_x( 'You can change the LD-%s enrollees by user ID (Proceed with caution)', 'placeholder: Course', 'learndash' ), learndash_get_custom_label( 'course' ) ), '' => '', ), 'value' => $this->setting_option_values['course_access_list_enabled'], 'default' => '', 'child_section_state' => ( 'on' === $this->setting_option_values['course_access_list_enabled'] ) ? 'open' : 'closed', 'help_text' => sprintf( // translators: placeholder: course. esc_html_x( 'Displays a list of %s enrollees by user ID. Note that not all enrollees may be reflected. We do not recommend editing this field.', 'placeholder: course.', 'learndash' ), learndash_get_custom_label_lower( 'course' ) ), ), 'course_access_list' => array( 'name' => 'course_access_list', 'type' => 'textarea', 'value' => $this->setting_option_values['course_access_list'], 'default' => '', 'parent_setting' => 'course_access_list_enabled', 'placeholder' => sprintf( // translators: placeholder: course. esc_html_x( 'Add a comma-list of user IDs to grant access to this %s', 'placeholder: course', 'learndash' ), learndash_get_custom_label( 'course' ) ), 'attrs' => array( 'rows' => '2', 'cols' => '57', ), ), ); /* if ( isset( $_GET['course_access_list_meta'] ) ) { $this->setting_option_fields['course_access_list_enabled']['value'] = 'on'; $this->setting_option_fields['course_access_list_enabled']['child_section_state'] = 'open'; $course_access_list_meta_array = learndash_get_course_users_access_from_meta( get_the_ID() ); if ( ! empty( $course_access_list_meta_array ) ) { $course_access_list_meta_array = learndash_convert_course_access_list( $course_access_list_meta_array, true ); } else { $course_access_list_meta_array = array(); } $course_access_list_array = learndash_convert_course_access_list( $this->setting_option_values['course_access_list'], true ); error_log('course_access_list_meta_array
'. print_r($course_access_list_meta_array, true) .''); error_log('course_access_list_array
'. print_r($course_access_list_array, true) .''); $course_access_list_diff_array = array_diff( $course_access_list_meta_array, $course_access_list_array ); if ( ! empty( $course_access_list_diff_array ) ) { $course_access_list_diff_str = learndash_convert_course_access_list( $course_access_list_diff_array ); } else { $course_access_list_diff_str = ''; } $this->setting_option_fields['course_access_list_meta'] = array( 'name' => 'course_access_list_meta', 'label' => esc_html__( 'Show Missing Users', 'learndash' ), 'type' => 'textarea', 'value' => $course_access_list_diff_str, 'default' => '', 'parent_setting' => 'course_access_list_enabled', 'attrs' => array( 'rows' => '2', 'cols' => '57', ), ); } else { $this->setting_option_fields['course_access_list_meta'] = array( 'name' => 'course_access_list_meta', 'label' => esc_html__( 'Show Missing Users', 'learndash' ), 'type' => 'html', 'value' => '' . esc_html( 'click to show missing users', 'learndash' ) .'', 'parent_setting' => 'course_access_list_enabled', ); } */ if ( false === learndash_use_legacy_course_access_list() ) { unset( $this->setting_option_fields['course_access_list_enabled'] ); unset( $this->setting_option_fields['course_access_list'] ); } $this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_metabox_key ); parent::load_settings_fields(); } protected function get_save_settings_fields_map_form_post_values( $post_values = array() ) { $settings_fields_map = $this->settings_fields_map; if ( ( isset( $post_values['course_price_type'] ) ) && ( ! empty( $post_values['course_price_type'] ) ) ) { if ( 'paynow' === $post_values['course_price_type'] ) { unset( $settings_fields_map['course_price_type_subscribe_price'] ); unset( $settings_fields_map['course_price_type_subscribe_billing_cycle'] ); unset( $settings_fields_map['course_price_type_closed_price'] ); unset( $settings_fields_map['course_price_type_closed_custom_button_label'] ); unset( $settings_fields_map['course_price_type_closed_custom_button_url'] ); } elseif ( 'subscribe' === $post_values['course_price_type'] ) { unset( $settings_fields_map['course_price_type_paynow_price'] ); unset( $settings_fields_map['course_price_type_closed_price'] ); unset( $settings_fields_map['course_price_type_closed_custom_button_label'] ); unset( $settings_fields_map['course_price_type_closed_custom_button_url'] ); } elseif ( 'closed' === $post_values['course_price_type'] ) { unset( $settings_fields_map['course_price_type_subscribe_price'] ); unset( $settings_fields_map['course_price_type_subscribe_billing_cycle'] ); unset( $settings_fields_map['course_price_type_paynow_price'] ); } else { unset( $settings_fields_map['course_price_type_paynow_price'] ); unset( $settings_fields_map['course_price_type_subscribe_price'] ); unset( $settings_fields_map['course_price_type_subscribe_billing_cycle'] ); unset( $settings_fields_map['course_price_type_closed_price'] ); unset( $settings_fields_map['course_price_type_closed_custom_button_label'] ); unset( $settings_fields_map['course_price_type_closed_custom_button_url'] ); } } return $settings_fields_map; } /** * Filter settings values for metabox before save to database. * * @param array $settings_values Array of settings values. * @param string $settings_metabox_key Metabox key. * @param string $settings_screen_id Screen ID. * @return array $settings_values. */ public function filter_saved_fields( $settings_values = array(), $settings_metabox_key = '', $settings_screen_id = '' ) { if ( ( $settings_screen_id === $this->settings_screen_id ) && ( $settings_metabox_key === $this->settings_metabox_key ) ) { if ( ! isset( $settings_values['course_price_type'] ) ) { $settings_values['course_price_type'] = ''; } if ( 'paynow' === $settings_values['course_price_type'] ) { $settings_values['custom_button_url'] = ''; $settings_values['course_price_billing_p3'] = ''; $settings_values['course_price_billing_t3'] = ''; } elseif ( 'subscribe' === $settings_values['course_price_type'] ) { $settings_values['custom_button_url'] = ''; } elseif ( 'closed' === $settings_values['course_price_type'] ) { $settings_values['course_price_billing_p3'] = ''; $settings_values['course_price_billing_t3'] = ''; } else { $settings_values['course_price'] = ''; $settings_values['custom_button_url'] = ''; $settings_values['course_price_billing_p3'] = ''; $settings_values['course_price_billing_t3'] = ''; } /** * Check the Course Materials set course_points_enabled/course_points/course_points_access. If 'course_points_enabled' setting is * 'on' then make sure 'course_points' and 'course_points_access' are not empty. */ if ( ( isset( $settings_values['course_points_enabled'] ) ) && ( 'on' === $settings_values['course_points_enabled'] ) ) { if ( ( isset( $settings_values['course_points'] ) ) && ( empty( $settings_values['course_points'] ) ) && ( isset( $settings_values['course_points_access'] ) ) && ( empty( $settings_values['course_points_access'] ) ) ) { $settings_values['course_points_enabled'] = ''; } } /** * Check the Lessons Per Page set course_prerequisite_enabled/course_prerequisite. If 'course_prerequisite_enabled' setting is * 'on' then make sure 'course_prerequisite' is not empty. */ if ( ( isset( $settings_values['course_prerequisite_enabled'] ) ) && ( 'on' === $settings_values['course_prerequisite_enabled'] ) ) { if ( ( isset( $settings_values['course_prerequisite'] ) ) && ( is_array( $settings_values['course_prerequisite'] ) ) && ( ! empty( $settings_values['course_prerequisite'] ) ) ) { $settings_values['course_prerequisite'] = array_diff( $settings_values['course_prerequisite'], array( 0 ) ); if ( empty( $settings_values['course_prerequisite'] ) ) { $settings_values['course_prerequisite_enabled'] = ''; } } else { $settings_values['course_prerequisite_enabled'] = ''; } } /** * Check the Lessons Per Page set expire_access/expire_access_days. If 'expire_access' setting is * 'on' then make sure 'expire_access_days' is not empty. */ if ( ( isset( $settings_values['expire_access'] ) ) && ( 'on' === $settings_values['expire_access'] ) ) { if ( ( isset( $settings_values['expire_access_days'] ) ) && ( empty( $settings_values['expire_access_days'] ) ) ) { $settings_values['expire_access'] = ''; } } /** * Check the Lessons Per Page set expire_access/expire_access_days. If 'expire_access' setting is * 'on' then make sure 'expire_access_days' is not empty. */ if ( ( isset( $settings_values['course_access_list_enabled'] ) ) && ( 'on' === $settings_values['course_access_list_enabled'] ) ) { if ( ( isset( $settings_values['course_access_list'] ) ) && ( empty( $settings_values['course_access_list'] ) ) ) { $settings_values['course_access_list_enabled'] = ''; } } $settings_values = apply_filters( 'learndash_settings_save_values', $settings_values, $this->settings_metabox_key ); } return $settings_values; } // End of functions. } add_filter( 'learndash_post_settings_metaboxes_init_' . learndash_get_post_type_slug( 'course' ), function( $metaboxes = array() ) { if ( ( ! isset( $metaboxes['LearnDash_Settings_Metabox_Course_Access_Settings'] ) ) && ( class_exists( 'LearnDash_Settings_Metabox_Course_Access_Settings' ) ) ) { $metaboxes['LearnDash_Settings_Metabox_Course_Access_Settings'] = LearnDash_Settings_Metabox_Course_Access_Settings::add_metabox_instance(); } return $metaboxes; }, 50, 1 ); } settings-metaboxes/class-ld-settings-metabox-topic-access-settings.php 0000666 00000020142 15214240575 0022320 0 ustar 00 settings_screen_id = 'sfwd-topic'; // Used within the Settings API to uniquely identify this section. $this->settings_metabox_key = 'learndash-topic-access-settings'; // Section label/header. $this->settings_section_label = sprintf( // translators: placeholder: Topic. esc_html_x( '%s Access Settings', 'placeholder: Topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ); $this->settings_section_description = sprintf( // translators: placeholder: topic. esc_html_x( 'Controls how, where, and when the %s can be accessed.', 'placeholder: topic', 'learndash' ), learndash_get_custom_label( 'topic' ) ); add_filter( 'learndash_metabox_save_fields_' . $this->settings_metabox_key, array( $this, 'filter_saved_fields' ), 30, 3 ); add_filter( 'learndash_show_metabox', array( $this, 'check_show_metabox' ), 50, 2 ); // Map internal settings field ID to legacy field ID. $this->settings_fields_map = array( 'course' => 'course', 'lesson' => 'lesson', ); parent::__construct(); } /** * Hook into filter before the metabox is registered in WP. * * @since 3.0 * @param boolean $show_metabox True or False to show metabox. * @param string $settings_metabox_key metabox key. * @return boolean $show_metabox */ public function check_show_metabox( $show_metabox, $settings_metabox_key = '' ) { if ( $settings_metabox_key === $this->settings_metabox_key ) { // IF Course shared Steps is enabled we don't show this metabox. if ( 'yes' === LearnDash_Settings_Section::get_section_setting( 'LearnDash_Settings_Courses_Builder', 'shared_steps' ) ) { $show_metabox = false; } } return $show_metabox; } /** * Initialize the metabox settings values. */ public function load_settings_values() { parent::load_settings_values(); if ( true === $this->settings_values_loaded ) { if ( ! isset( $this->setting_option_values['course'] ) ) { $this->setting_option_values['course'] = ''; } if ( ! isset( $this->setting_option_values['lesson'] ) ) { $this->setting_option_values['lesson'] = ''; } } } /** * Initialize the metabox settings fields. */ public function load_settings_fields() { global $sfwd_lms; $select_course_options = $sfwd_lms->select_a_course(); if ( ( defined( 'LEARNDASH_SELECT2_LIB' ) ) && ( true === apply_filters( 'learndash_select2_lib', LEARNDASH_SELECT2_LIB ) ) ) { $select_course_options_default = array( '-1' => sprintf( // translators: placeholder: course. esc_html_x( 'Search or select a %s…', 'placeholder: course', 'learndash' ), learndash_get_custom_label( 'course' ) ), ); } else { $select_course_options_default = array( '' => sprintf( // translators: placeholder: course. esc_html_x( 'Select %s', 'placeholder: course', 'learndash' ), learndash_get_custom_label( 'course' ) ), ); } $select_course_options = $select_course_options_default + $select_course_options; if ( ( defined( 'LEARNDASH_SELECT2_LIB' ) ) && ( true === apply_filters( 'learndash_select2_lib', LEARNDASH_SELECT2_LIB ) ) ) { $select_lesson_options_default = array( '-1' => sprintf( // translators: placeholder: Lesson. esc_html_x( 'Search or select a %s…', 'placeholder: Lesson', 'learndash' ), learndash_get_custom_label( 'lesson' ) ), ); } else { $select_lesson_options_default = array( '' => sprintf( // translators: placeholder: Lesson. esc_html_x( 'Select %s', 'placeholder: Lesson', 'learndash' ), learndash_get_custom_label( 'lesson' ) ), ); } $select_lesson_options = array(); if ( ( isset( $this->setting_option_values['course'] ) ) && ( ! empty( $this->setting_option_values['course'] ) ) ) { $select_lesson_options = $sfwd_lms->select_a_lesson( absint( $this->setting_option_values['course'] ) ); if ( ( is_array( $select_lesson_options ) ) && ( ! empty( $select_lesson_options ) ) ) { if ( isset( $select_lesson_options[0] ) ) { unset( $select_lesson_options[0] ); } $select_lesson_options = $select_lesson_options_default + $select_lesson_options; } else { $select_lesson_options = $select_lesson_options_default; } } else { $select_lesson_options = $select_lesson_options_default; } $this->setting_option_fields = array( 'course' => array( 'name' => 'course', 'label' => sprintf( // translators: placeholders: course. esc_html_x( 'Associated %s', 'Associated Course Label', 'learndash' ), learndash_get_custom_label( 'course' ) ), 'type' => 'select', 'lazy_load' => true, 'help_text' => sprintf( // translators: placeholders: Topic, Course. esc_html_x( 'Associate this %1$s with a %2$s.', 'placeholder: Topic, Course.', 'learndash' ), learndash_get_custom_label( 'topic' ), learndash_get_custom_label( 'course' ) ), 'default' => '', 'value' => $this->setting_option_values['course'], 'options' => $select_course_options, 'attrs' => array( 'data-ld_selector_nonce' => wp_create_nonce( 'sfwd-courses' ), 'data-ld_selector_default' => '1', ), ), 'lesson' => array( 'name' => 'lesson', 'label' => sprintf( // translators: placeholder: Lesson. esc_html_x( 'Associated %s', 'placeholder: Lesson', 'learndash' ), learndash_get_custom_label( 'lesson' ) ), 'type' => 'select', 'lazy_load' => true, 'help_text' => sprintf( // translators: placeholders: Lesson, Course. esc_html_x( 'Associate this %1$s with a %2$s.', 'placeholders: Lesson, Course', 'learndash' ), learndash_get_custom_label( 'lesson' ), learndash_get_custom_label( 'course' ) ), 'default' => '', 'value' => $this->setting_option_values['lesson'], 'options' => $select_lesson_options, 'attrs' => array( 'data-ld_selector_nonce' => wp_create_nonce( 'sfwd-lessons' ), 'data-ld_selector_default' => '1', ), ), ); $this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_metabox_key ); parent::load_settings_fields(); } /** * Filter settings values for metabox before save to database. * * @param array $settings_values Array of settings values. * @param string $settings_metabox_key Metabox key. * @param string $settings_screen_id Screen ID. * @return array $settings_values. */ public function filter_saved_fields( $settings_values = array(), $settings_metabox_key = '', $settings_screen_id = '' ) { if ( ( $settings_screen_id === $this->settings_screen_id ) && ( $settings_metabox_key === $this->settings_metabox_key ) ) { if ( ( ! isset( $settings_values['course'] ) ) || ( '-1' === $settings_values['course'] ) ) { $settings_values['course'] = ''; } if ( ( ! isset( $settings_values['lesson'] ) ) || ( '-1' === $settings_values['lesson'] ) ) { $settings_values['lesson'] = ''; } } return $settings_values; } // End of functions. } add_filter( 'learndash_post_settings_metaboxes_init_' . learndash_get_post_type_slug( 'topic' ), function( $metaboxes = array() ) { if ( ( ! isset( $metaboxes['LearnDash_Settings_Metabox_Topic_Access_Settings'] ) ) && ( class_exists( 'LearnDash_Settings_Metabox_Topic_Access_Settings' ) ) ) { $metaboxes['LearnDash_Settings_Metabox_Topic_Access_Settings'] = LearnDash_Settings_Metabox_Topic_Access_Settings::add_metabox_instance(); } return $metaboxes; }, 50, 1 ); } settings-metaboxes/class-ld-settings-metabox-quiz-display-content.php 0000666 00000114144 15214240575 0022216 0 ustar 00 settings_screen_id = 'sfwd-quiz'; // Used within the Settings API to uniquely identify this section. $this->settings_metabox_key = 'learndash-quiz-display-content-settings'; // Section label/header. $this->settings_section_label = esc_html__( 'Display and Content Options', 'learndash' ); // Used to show the section description above the fields. Can be empty. $this->settings_section_description = sprintf( // translators: placeholder: quiz. esc_html_x( 'Controls how the %s will look and what will be displayed', 'placeholder: quiz', 'learndash' ), learndash_get_custom_label_lower( 'quiz' ) ); add_filter( 'learndash_metabox_save_fields_' . $this->settings_metabox_key, array( $this, 'filter_saved_fields' ), 30, 3 ); // Map internal settings field ID to legacy field ID. $this->settings_fields_map = array( 'quiz_materials_enabled' => 'quiz_materials_enabled', 'quiz_materials' => 'quiz_materials', 'custom_sorting' => 'custom_sorting', 'autostart' => 'autostart', 'showReviewQuestion' => 'showReviewQuestion', 'quizSummaryHide' => 'quizSummaryHide', 'skipQuestionDisabled' => 'skipQuestionDisabled', 'sortCategories' => 'sortCategories', 'questionRandom' => 'questionRandom', 'showMaxQuestion' => 'showMaxQuestion', 'showMaxQuestionValue' => 'showMaxQuestionValue', 'showPoints' => 'showPoints', 'showCategory' => 'showCategory', 'hideQuestionPositionOverview' => 'hideQuestionPositionOverview', 'hideQuestionNumbering' => 'hideQuestionNumbering', 'numberedAnswer' => 'numberedAnswer', 'answerRandom' => 'answerRandom', 'quizModus' => 'quizModus', 'quizModus_multiple_questionsPerPage' => 'quizModus_multiple_questionsPerPage', 'quizModus_single_back_button' => 'quizModus_single_back_button', 'quizModus_single_feedback' => 'quizModus_single_feedback', 'titleHidden' => 'titleHidden', ); parent::__construct(); } /** * Used to save the settings fields back to the global $_POST object so * the WPProQuiz normal form processing can take place. * * @since 3.0 * @param object $pro_quiz_edit WpProQuiz_Controller_Quiz instance (not used). * @param array $settings_values Array of settings fields. */ public function save_fields_to_post( $pro_quiz_edit, $settings_values = array() ) { $_POST['autostart'] = $settings_values['autostart']; $_POST['showReviewQuestion'] = $settings_values['showReviewQuestion']; $_POST['quizSummaryHide'] = $settings_values['quizSummaryHide']; $_POST['skipQuestionDisabled'] = $settings_values['skipQuestionDisabled']; $_POST['sortCategories'] = $settings_values['sortCategories']; $_POST['questionRandom'] = $settings_values['questionRandom']; $_POST['showMaxQuestion'] = $settings_values['showMaxQuestion']; $_POST['showMaxQuestionValue'] = $settings_values['showMaxQuestionValue']; $_POST['answerRandom'] = $settings_values['answerRandom']; $_POST['showPoints'] = $settings_values['showPoints']; $_POST['showCategory'] = $settings_values['showCategory']; $_POST['hideQuestionPositionOverview'] = $settings_values['hideQuestionPositionOverview']; $_POST['hideQuestionNumbering'] = $settings_values['hideQuestionNumbering']; $_POST['numberedAnswer'] = $settings_values['numberedAnswer']; $_POST['quizModus'] = $settings_values['quizModus']; $_POST['questionsPerPage'] = $settings_values['quizModus_multiple_questionsPerPage']; $_POST['titleHidden'] = $settings_values['titleHidden']; } /** * Initialize the metabox settings values. */ public function load_settings_values() { parent::load_settings_values(); $this->quiz_edit = $this->init_quiz_edit( $this->_post ); $this->ld_quiz_questions_object = LDLMS_Factory_Post::quiz_questions( $this->_post->ID ); if ( true === $this->settings_values_loaded ) { $questionMapper = new WpProQuiz_Model_QuestionMapper(); $questions = $questionMapper->fetchAll( $this->quiz_edit['quiz'] ); if ( ( is_array( $questions ) ) && ( ! empty( $questions ) ) ) { $this->questions_count = count( $questions ); } if ( ! isset( $this->setting_option_values['quiz_materials'] ) ) { $this->setting_option_values['quiz_materials'] = ''; } if ( ! empty( $this->setting_option_values['quiz_materials'] ) ) { $this->setting_option_values['quiz_materials_enabled'] = 'on'; } else { $this->setting_option_values['quiz_materials_enabled'] = ''; } if ( $this->quiz_edit['quiz'] ) { $this->setting_option_values['autostart'] = $this->quiz_edit['quiz']->isAutostart(); if ( true === $this->setting_option_values['autostart'] ) { $this->setting_option_values['autostart'] = 'on'; } else { $this->setting_option_values['autostart'] = ''; } $this->setting_option_values['showReviewQuestion'] = $this->quiz_edit['quiz']->isShowReviewQuestion(); if ( true === $this->setting_option_values['showReviewQuestion'] ) { $this->setting_option_values['showReviewQuestion'] = 'on'; } else { $this->setting_option_values['showReviewQuestion'] = ''; } $this->setting_option_values['quizSummaryHide'] = $this->quiz_edit['quiz']->isQuizSummaryHide(); if ( true === $this->setting_option_values['quizSummaryHide'] ) { $this->setting_option_values['quizSummaryHide'] = ''; } else { $this->setting_option_values['quizSummaryHide'] = 'on'; } $this->setting_option_values['skipQuestionDisabled'] = $this->quiz_edit['quiz']->isSkipQuestionDisabled(); if ( true === $this->setting_option_values['skipQuestionDisabled'] ) { $this->setting_option_values['skipQuestionDisabled'] = ''; } else { $this->setting_option_values['skipQuestionDisabled'] = 'on'; } $this->setting_option_values['sortCategories'] = $this->quiz_edit['quiz']->isSortCategories(); if ( true === $this->setting_option_values['sortCategories'] ) { $this->setting_option_values['sortCategories'] = 'on'; } else { $this->setting_option_values['sortCategories'] = ''; } $this->setting_option_values['questionRandom'] = $this->quiz_edit['quiz']->isQuestionRandom(); if ( true === $this->setting_option_values['questionRandom'] ) { $this->setting_option_values['questionRandom'] = 'on'; } else { $this->setting_option_values['questionRandom'] = ''; } $this->setting_option_values['showMaxQuestion'] = $this->quiz_edit['quiz']->isShowMaxQuestion(); if ( true === $this->setting_option_values['showMaxQuestion'] ) { $this->setting_option_values['showMaxQuestion'] = 'on'; } else { $this->setting_option_values['showMaxQuestion'] = ''; } $this->setting_option_values['showMaxQuestionValue'] = $this->quiz_edit['quiz']->getShowMaxQuestionValue(); if ( ! empty( $this->setting_option_values['showMaxQuestionValue'] ) ) { $this->setting_option_values['showMaxQuestionValue'] = absint( $this->setting_option_values['showMaxQuestionValue'] ); } else { $this->setting_option_values['showMaxQuestionValue'] = ''; } if ( absint( $this->setting_option_values['showMaxQuestionValue'] ) > $this->questions_count ) { $this->setting_option_values['showMaxQuestionValue'] = $this->questions_count; } if ( 'on' === $this->setting_option_values['questionRandom'] ) { if ( 'on' !== $this->setting_option_values['showMaxQuestion'] ) { $this->setting_option_values['showMaxQuestionValue'] = 0; } } else { $this->setting_option_values['showMaxQuestion'] = ''; $this->setting_option_values['showMaxQuestionValue'] = 0; } if ( ( 'on' === $this->setting_option_values['sortCategories'] ) || ( 'on' === $this->setting_option_values['questionRandom'] ) ) { $this->setting_option_values['custom_sorting'] = 'on'; } else { $this->setting_option_values['custom_sorting'] = ''; } $this->setting_option_values['showPoints'] = $this->quiz_edit['quiz']->isShowPoints(); if ( true === $this->quiz_edit['quiz']->isShowPoints() ) { $this->setting_option_values['showPoints'] = 'on'; } else { $this->setting_option_values['showPoints'] = ''; } $this->setting_option_values['showCategory'] = $this->quiz_edit['quiz']->isShowCategory(); if ( true === $this->setting_option_values['showCategory'] ) { $this->setting_option_values['showCategory'] = 'on'; } else { $this->setting_option_values['showCategory'] = ''; } $this->setting_option_values['hideQuestionPositionOverview'] = $this->quiz_edit['quiz']->isHideQuestionPositionOverview(); if ( true !== $this->setting_option_values['hideQuestionPositionOverview'] ) { $this->setting_option_values['hideQuestionPositionOverview'] = 'on'; } else { $this->setting_option_values['hideQuestionPositionOverview'] = ''; } $this->setting_option_values['hideQuestionNumbering'] = $this->quiz_edit['quiz']->isHideQuestionNumbering(); if ( true !== $this->setting_option_values['hideQuestionNumbering'] ) { $this->setting_option_values['hideQuestionNumbering'] = 'on'; } else { $this->setting_option_values['hideQuestionNumbering'] = ''; } $this->setting_option_values['numberedAnswer'] = $this->quiz_edit['quiz']->isNumberedAnswer(); if ( true === $this->setting_option_values['numberedAnswer'] ) { $this->setting_option_values['numberedAnswer'] = 'on'; } else { $this->setting_option_values['numberedAnswer'] = ''; } $this->setting_option_values['answerRandom'] = $this->quiz_edit['quiz']->isAnswerRandom(); if ( true === $this->setting_option_values['answerRandom'] ) { $this->setting_option_values['answerRandom'] = 'on'; } else { $this->setting_option_values['answerRandom'] = ''; } $this->setting_option_values['quizModus'] = ''; $this->setting_option_values['quizModus_single_feedback'] = ''; $this->setting_option_values['quizModus_single_back_button'] = ''; $this->setting_option_values['quizModus_multiple_questionsPerPage'] = 0; $this->setting_option_values['quizModus'] = (int) $this->quiz_edit['quiz']->getQuizModus(); if ( 0 === $this->setting_option_values['quizModus'] ) { $this->setting_option_values['quizModus'] = 'single'; $this->setting_option_values['quizModus_single_feedback'] = 'end'; } elseif ( 1 === $this->setting_option_values['quizModus'] ) { $this->setting_option_values['quizModus'] = 'single'; $this->setting_option_values['quizModus_single_feedback'] = 'end'; $this->setting_option_values['quizModus_single_back_button'] = 'on'; } elseif ( 2 === $this->setting_option_values['quizModus'] ) { $this->setting_option_values['quizModus'] = 'single'; $this->setting_option_values['quizModus_single_feedback'] = 'each'; } elseif ( 3 === $this->setting_option_values['quizModus'] ) { $this->setting_option_values['quizModus'] = 'multiple'; $this->setting_option_values['quizModus_multiple_questionsPerPage'] = (int) $this->quiz_edit['quiz']->getQuestionsPerPage(); } $this->setting_option_values['titleHidden'] = $this->quiz_edit['quiz']->isTitleHidden(); if ( true !== $this->setting_option_values['titleHidden'] ) { $this->setting_option_values['titleHidden'] = 'on'; } else { $this->setting_option_values['titleHidden'] = ''; } } if ( ( 'on' === $this->setting_option_values['showPoints'] ) || ( 'on' === $this->setting_option_values['showCategory'] ) || ( 'on' === $this->setting_option_values['hideQuestionPositionOverview'] ) || ( 'on' === $this->setting_option_values['hideQuestionNumbering'] ) || ( 'on' === $this->setting_option_values['numberedAnswer'] ) ) { $this->setting_option_values['custom_question_elements'] = 'on'; } else { $this->setting_option_values['custom_question_elements'] = ''; } } foreach ( $this->settings_fields_map as $_internal => $_external ) { if ( ! isset( $this->setting_option_values[ $_internal ] ) ) { $this->setting_option_values[ $_internal ] = ''; } } } /** * Initialize the metabox settings fields. */ public function load_settings_fields() { global $sfwd_lms; //apply_filters( $this->settings_screen_id . '_display_settings', $this->settings_fields_legacy, $this->settings_screen_id, $this->settings_values_legacy ); $this->setting_option_fields = array( 'quizModus_single_back_button' => array( 'name' => 'quizModus_single_back_button', 'label_none' => true, 'input_full' => true, 'type' => 'checkbox', 'value' => $this->setting_option_values['quizModus_single_back_button'], 'default' => '', 'options' => array( 'on' => esc_html__( 'Display Back button', 'learndash' ), ), ), ); parent::load_settings_fields(); $this->settings_sub_option_fields['quizModus_single_back_button_fields'] = $this->setting_option_fields; $this->setting_option_fields = array( 'quizModus_single_feedback' => array( 'name' => 'quizModus_single_feedback', 'label_none' => true, 'input_full' => true, 'type' => 'radio', 'value' => $this->setting_option_values['quizModus_single_feedback'], 'default' => 'end', 'options' => array( 'end' => array( 'label' => esc_html__( 'Display results at the end only', 'learndash' ), 'inline_fields' => array( 'quizModus_single' => $this->settings_sub_option_fields['quizModus_single_back_button_fields'], ), 'inner_section_state' => ( 'end' === $this->setting_option_values['quizModus_single_feedback'] ) ? 'open' : 'closed', ), 'each' => array( 'label' => esc_html__( 'Display results after each submitted answer', 'learndash' ), ), ), ), ); parent::load_settings_fields(); $this->settings_sub_option_fields['quizModus_single_fields'] = $this->setting_option_fields; $this->setting_option_fields = array( 'quizModus_multiple_questionsPerPage' => array( 'name' => 'quizModus_multiple_questionsPerPage', 'type' => 'number', 'class' => 'small-text', 'label_none' => true, 'input_full' => true, 'input_label' => sprintf( // translators: placeholder: questions. esc_html_x( '%s per page (0 = all)', 'placeholder: questions', 'learndash' ), learndash_get_custom_label_lower( 'questions' ) ), 'attrs' => array( 'step' => 1, 'min' => 0, ), 'value' => $this->setting_option_values['quizModus_multiple_questionsPerPage'], 'default' => 0, ), ); parent::load_settings_fields(); $this->settings_sub_option_fields['quizModus_multiple_fields'] = $this->setting_option_fields; $this->setting_option_fields = array( 'showMaxQuestionValue' => array( 'name' => 'showMaxQuestionValue', 'type' => 'number', 'class' => 'small-text', 'label_none' => true, 'input_full' => true, 'input_label' => sprintf( // translators: placeholder: questions. esc_html_x( 'out of %1$d %2$s.', 'placeholder: count of questions, questions label.', 'learndash' ), $this->questions_count, learndash_get_custom_label_lower( 'questions' ) ), 'attrs' => array( 'step' => 1, 'min' => 0, 'max' => $this->questions_count, ), 'value' => $this->setting_option_values['showMaxQuestionValue'], 'default' => 0, ), ); parent::load_settings_fields(); $this->settings_sub_option_fields['showMaxQuestionValue_fields'] = $this->setting_option_fields; $this->setting_option_fields = array( 'quiz_materials_enabled' => array( 'name' => 'quiz_materials_enabled', 'type' => 'checkbox-switch', 'label' => sprintf( // translators: placeholder: Quiz. esc_html_x( '%s Materials', 'placeholder: Quiz', 'learndash' ), learndash_get_custom_label( 'quiz' ) ), 'help_text' => sprintf( // translators: placeholder: quiz, quiz. esc_html_x( 'List and display support materials for the %1$s. This is visible to any user having access to the %2$s.', 'placeholder: quiz, quiz', 'learndash' ), learndash_get_custom_label_lower( 'quiz' ), learndash_get_custom_label_lower( 'quiz' ) ), 'value' => $this->setting_option_values['quiz_materials_enabled'], 'default' => '', 'options' => array( 'on' => sprintf( // translators: placeholder: Quiz. esc_html_x( 'Any content added below is displayed on the %s page', 'placeholder: Quiz', 'learndash' ), learndash_get_custom_label( 'quiz' ) ), '' => '', ), 'child_section_state' => ( 'on' === $this->setting_option_values['quiz_materials_enabled'] ) ? 'open' : 'closed', ), 'quiz_materials' => array( 'name' => 'quiz_materials', 'type' => 'wpeditor', 'parent_setting' => 'quiz_materials_enabled', 'value' => $this->setting_option_values['quiz_materials'], 'default' => '', 'placeholder' => esc_html__( 'Add a list of needed documents or URLs. This field supports HTML.', 'learndash' ), 'editor_args' => array( 'textarea_name' => $this->settings_metabox_key . '[quiz_materials]', 'textarea_rows' => 3, ), ), 'autostart' => array( 'name' => 'autostart', 'type' => 'checkbox', 'label' => esc_html__( 'Autostart', 'learndash' ), 'value' => $this->setting_option_values['autostart'], 'default' => '', 'options' => array( 'on' => sprintf( // translators: placeholder: Quiz. esc_html_x( 'Start automatically, without the "Start %s" button', 'placeholder: Quiz', 'learndash' ), learndash_get_custom_label( 'quiz' ) ), ), ), 'quizModus' => array( 'name' => 'quizModus', 'label' => sprintf( // translators: placeholder: Question. esc_html_x( '%s Display', 'placeholder: Question', 'learndash' ), learndash_get_custom_label( 'question' ) ), 'type' => 'select', 'default' => 'single', 'value' => $this->setting_option_values['quizModus'], 'options' => array( 'single' => array( 'label' => sprintf( // translators: placeholder: question. esc_html_x( 'One %s at a time', 'placeholder: question', 'learndash' ), learndash_get_custom_label_lower( 'question' ) ), 'inline_fields' => array( 'quizModus_single' => $this->settings_sub_option_fields['quizModus_single_fields'], ), 'inner_section_state' => ( 'single' === $this->setting_option_values['quizModus'] ) ? 'open' : 'closed', ), 'multiple' => array( 'label' => sprintf( // translators: placeholder: questions. esc_html_x( 'All %s at once (or paginated)', 'placeholder: questions', 'learndash' ), learndash_get_custom_label_lower( 'questions' ) ), 'inline_fields' => array( 'quizModus_multiple' => $this->settings_sub_option_fields['quizModus_multiple_fields'], ), 'inner_section_state' => ( 'multiple' === $this->setting_option_values['quizModus'] ) ? 'open' : 'closed', ), ), ), 'showReviewQuestion' => array( 'name' => 'showReviewQuestion', 'type' => 'checkbox-switch', 'label' => sprintf( // translators: placeholder: Question. esc_html_x( '%s Overview Table', 'placeholder: Question', 'learndash' ), learndash_get_custom_label( 'question' ) ), 'value' => $this->setting_option_values['showReviewQuestion'], 'default' => '', 'options' => array( '' => '', 'on' => sprintf( // translators: placeholder: Quiz, Questions. esc_html_x( 'An overview table will be shown for all %s.', 'placeholder: Questions', 'learndash' ), learndash_get_custom_label_lower( 'questions' ) ), ), 'child_section_state' => ( 'on' === $this->setting_option_values['showReviewQuestion'] ) ? 'open' : 'closed', ), 'quizSummaryHide' => array( 'name' => 'quizSummaryHide', 'type' => 'checkbox-switch', 'label' => sprintf( // translators: placeholder: Quiz. esc_html_x( '%s Summary', 'placeholder: Quiz', 'learndash' ), learndash_get_custom_label( 'quiz' ) ), 'value' => $this->setting_option_values['quizSummaryHide'], 'default' => '', 'options' => array( '' => '', 'on' => esc_html__( 'Display a summary table before submission', 'learndash' ), ), 'parent_setting' => 'showReviewQuestion', ), 'skipQuestionDisabled' => array( 'name' => 'skipQuestionDisabled', 'type' => 'checkbox-switch', 'label' => sprintf( // translators: placeholder: Question. esc_html_x( 'Skip %s', 'placeholder: Question', 'learndash' ), learndash_get_custom_label( 'question' ) ), 'value' => $this->setting_option_values['skipQuestionDisabled'], 'default' => '', 'options' => array( 'on' => '', ), 'parent_setting' => 'showReviewQuestion', ), 'custom_sorting' => array( 'name' => 'custom_sorting', 'type' => 'checkbox-switch', 'label' => sprintf( // translators: placeholder: Question. esc_html_x( 'Custom %s Ordering', 'placeholder: Question', 'learndash' ), learndash_get_custom_label( 'question' ) ), 'value' => $this->setting_option_values['custom_sorting'], 'default' => '', 'options' => array( 'on' => '', ), 'child_section_state' => ( 'on' === $this->setting_option_values['custom_sorting'] ) ? 'open' : 'closed', ), 'sortCategories' => array( 'name' => 'sortCategories', 'type' => 'checkbox', 'label' => esc_html__( 'Sort by Category', 'learndash' ), 'value' => $this->setting_option_values['sortCategories'], 'default' => '', 'options' => array( 'on' => '', ), 'parent_setting' => 'custom_sorting', ), 'questionRandom' => array( 'name' => 'questionRandom', 'type' => 'checkbox-switch', 'label' => esc_html__( 'Randomize Order', 'learndash' ), 'value' => $this->setting_option_values['questionRandom'], 'default' => '', 'options' => array( 'on' => '', ), 'parent_setting' => 'custom_sorting', 'child_section_state' => ( 'on' === $this->setting_option_values['questionRandom'] ) ? 'open' : 'closed', ), 'showMaxQuestion' => array( 'name' => 'showMaxQuestion', 'label' => '', 'type' => 'radio', 'value' => $this->setting_option_values['showMaxQuestion'], 'default' => '', 'options' => array( '' => array( 'label' => sprintf( // translators: placeholder: questions. esc_html_x( 'Display all %s', 'placeholder: questions', 'learndash' ), learndash_get_custom_label_lower( 'questions' ) ), ), 'on' => array( 'label' => sprintf( // translators: placeholder: questions. esc_html_x( 'Display subset of %s', 'placeholder: questions', 'learndash' ), learndash_get_custom_label_lower( 'questions' ) ), 'inline_fields' => array( 'showMaxQuestionValue_fields' => $this->settings_sub_option_fields['showMaxQuestionValue_fields'], ), 'inner_section_state' => ( 'on' === $this->setting_option_values['showMaxQuestion'] ) ? 'open' : 'closed', ), ), 'parent_setting' => 'questionRandom', ), 'custom_question_elements' => array( 'name' => 'custom_question_elements', 'type' => 'checkbox-switch', 'label' => sprintf( // translators: placeholder: Question. esc_html_x( 'Additional %s Options', 'placeholder: Question', 'learndash' ), learndash_get_custom_label( 'question' ) ), 'value' => $this->setting_option_values['custom_question_elements'], 'default' => '', 'options' => array( '' => '', 'on' => sprintf( // translators: placeholder: Question. esc_html_x( 'Any enabled elements below will be displayed in each %s', 'placeholder: Question', 'learndash' ), learndash_get_custom_label( 'question' ) ), ), 'child_section_state' => ( 'on' === $this->setting_option_values['custom_question_elements'] ) ? 'open' : 'closed', ), 'showPoints' => array( 'name' => 'showPoints', 'type' => 'checkbox-switch', 'label' => esc_html__( 'Point Value', 'learndash' ), 'value' => $this->setting_option_values['showPoints'], 'default' => '', 'options' => array( 'on' => '', ), 'parent_setting' => 'custom_question_elements', ), 'showCategory' => array( 'name' => 'showCategory', 'type' => 'checkbox-switch', 'label' => sprintf( // translators: placeholder: Question. esc_html_x( '%s Category', 'placeholder: Question', 'learndash' ), learndash_get_custom_label( 'question' ) ), 'value' => $this->setting_option_values['showCategory'], 'default' => '', 'options' => array( 'on' => '', ), 'parent_setting' => 'custom_question_elements', ), 'hideQuestionPositionOverview' => array( 'name' => 'hideQuestionPositionOverview', 'type' => 'checkbox-switch', 'label' => sprintf( // translators: placeholder: Question. esc_html_x( '%s Position', 'placeholder: Question', 'learndash' ), learndash_get_custom_label( 'question' ) ), 'value' => $this->setting_option_values['hideQuestionPositionOverview'], 'default' => '', 'options' => array( 'on' => '', ), 'parent_setting' => 'custom_question_elements', ), 'hideQuestionNumbering' => array( 'name' => 'hideQuestionNumbering', 'type' => 'checkbox-switch', 'label' => sprintf( // translators: placeholder: Question. esc_html_x( '%s Numbering', 'placeholder: Question', 'learndash' ), learndash_get_custom_label( 'question' ) ), 'value' => $this->setting_option_values['hideQuestionNumbering'], 'default' => '', 'options' => array( 'on' => '', ), 'parent_setting' => 'custom_question_elements', ), 'numberedAnswer' => array( 'name' => 'numberedAnswer', 'type' => 'checkbox-switch', 'label' => esc_html__( 'Number Answers', 'learndash' ), 'value' => $this->setting_option_values['numberedAnswer'], 'default' => '', 'options' => array( 'on' => '', ), 'parent_setting' => 'custom_question_elements', ), 'answerRandom' => array( 'name' => 'answerRandom', 'type' => 'checkbox-switch', 'label' => esc_html__( 'Randomize Answers', 'learndash' ), 'help_text' => sprintf( // translators: placeholder: question. esc_html_x( 'Answer display will be randomized within any given %s.', 'placeholder: question.', 'learndash' ), learndash_get_custom_label_lower( 'question' ) ), 'value' => $this->setting_option_values['answerRandom'], 'default' => '', 'options' => array( 'on' => '', ), 'parent_setting' => 'custom_question_elements', ), 'titleHidden' => array( 'name' => 'titleHidden', 'type' => 'checkbox-switch', 'label' => sprintf( // translators: placeholder: Quiz. esc_html_x( '%s Title', 'placeholder: Quiz', 'learndash' ), learndash_get_custom_label( 'quiz' ) ), 'value' => $this->setting_option_values['titleHidden'], 'default' => '', 'help_text' => sprintf( // translators: placeholder: quiz, Quiz, Quizzes. esc_html_x( 'A second %1$s title will be displayed on the %2$s Post. This option is recommended if displaying %3$s via Shortcode.', 'placeholder: quiz, Quiz, Quizzes.', 'learndash' ), learndash_get_custom_label_lower( 'quiz' ), learndash_get_custom_label( 'quiz' ), learndash_get_custom_label( 'quizzes' ) ), 'options' => array( '' => sprintf( // translators: placeholder: Quiz. esc_html_x( 'Only the %s Post title is shown', 'placeholder: Quiz', 'learndash' ), learndash_get_custom_label( 'quiz' ) ), 'on' => sprintf( // translators: placeholder: Quiz, Quiz, quiz. esc_html_x( 'The %1$s Title is displayed in addition to the %2$s Post title. Recommended for %3$s shortcode usage.', 'placeholder: Quiz, Quiz, quiz', 'learndash' ), learndash_get_custom_label( 'quiz' ), learndash_get_custom_label( 'quiz' ), learndash_get_custom_label_lower( 'quiz' ) ), ), ), ); $this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_metabox_key ); parent::load_settings_fields(); } /** * Filter settings values for metabox before save to database. * * @param array $settings_values Array of settings values. * @param string $settings_metabox_key Metabox key. * @param string $settings_screen_id Screen ID. * @return array $settings_values. */ public function filter_saved_fields( $settings_values = array(), $settings_metabox_key = '', $settings_screen_id = '' ) { if ( ( $settings_screen_id === $this->settings_screen_id ) && ( $settings_metabox_key === $this->settings_metabox_key ) ) { if ( ( 'on' !== $settings_values['quiz_materials_enabled'] ) || ( empty( $settings_values['quiz_materials'] ) ) ) { $settings_values['quiz_materials_enabled'] = ''; $settings_values['quiz_materials'] = ''; } if ( ( isset( $settings_values['autostart'] ) ) && ( 'on' === $settings_values['autostart'] ) ) { $settings_values['autostart'] = true; } else { $settings_values['autostart'] = false; } if ( ( isset( $settings_values['showReviewQuestion'] ) ) && ( 'on' === $settings_values['showReviewQuestion'] ) ) { $settings_values['showReviewQuestion'] = true; } else { $settings_values['showReviewQuestion'] = false; } if ( ( isset( $settings_values['quizSummaryHide'] ) ) && ( 'on' === $settings_values['quizSummaryHide'] ) ) { $settings_values['quizSummaryHide'] = false; } else { $settings_values['quizSummaryHide'] = true; } if ( ( isset( $settings_values['skipQuestionDisabled'] ) ) && ( 'on' === $settings_values['skipQuestionDisabled'] ) ) { $settings_values['skipQuestionDisabled'] = false; } else { $settings_values['skipQuestionDisabled'] = true; } if ( ( isset( $settings_values['sortCategories'] ) ) && ( 'on' === $settings_values['sortCategories'] ) ) { $settings_values['sortCategories'] = true; } else { $settings_values['sortCategories'] = false; } if ( ( isset( $settings_values['questionRandom'] ) ) && ( 'on' === $settings_values['questionRandom'] ) ) { $settings_values['questionRandom'] = true; } else { $settings_values['questionRandom'] = false; } if ( ( isset( $settings_values['answerRandom'] ) ) && ( 'on' === $settings_values['answerRandom'] ) ) { $settings_values['answerRandom'] = true; } else { $settings_values['answerRandom'] = false; } if ( ( isset( $settings_values['showMaxQuestion'] ) ) && ( 'on' === $settings_values['showMaxQuestion'] ) ) { $settings_values['showMaxQuestion'] = true; } else { $settings_values['showMaxQuestion'] = false; } if ( ( isset( $settings_values['showMaxQuestionValue'] ) ) && ( ! empty( $settings_values['showMaxQuestionValue'] ) ) ) { $settings_values['showMaxQuestionValue'] = absint( $settings_values['showMaxQuestionValue'] ); if ( empty( $settings_values['showMaxQuestionValue'] ) ) { $settings_values['showMaxQuestionValue'] = ''; } } else { $settings_values['showMaxQuestion'] = ''; } //if ( ( isset( $settings_values['answerRandom'] ) ) && ( 'on' === $settings_values['answerRandom'] ) ) { // $settings_values['answerRandom'] = true; //} else { // $settings_values['answerRandom'] = false; //} if ( ( isset( $settings_values['showPoints'] ) ) && ( 'on' === $settings_values['showPoints'] ) ) { $settings_values['showPoints'] = true; } else { $settings_values['showPoints'] = false; } if ( ( isset( $settings_values['showCategory'] ) ) && ( 'on' === $settings_values['showCategory'] ) ) { $settings_values['showCategory'] = true; } else { $settings_values['showCategory'] = false; } if ( ( isset( $settings_values['hideQuestionPositionOverview'] ) ) && ( 'on' === $settings_values['hideQuestionPositionOverview'] ) ) { $settings_values['hideQuestionPositionOverview'] = false; } else { $settings_values['hideQuestionPositionOverview'] = true; } if ( ( isset( $settings_values['hideQuestionNumbering'] ) ) && ( 'on' === $settings_values['hideQuestionNumbering'] ) ) { $settings_values['hideQuestionNumbering'] = false; } else { $settings_values['hideQuestionNumbering'] = true; } if ( ( isset( $settings_values['numberedAnswer'] ) ) && ( 'on' === $settings_values['numberedAnswer'] ) ) { $settings_values['numberedAnswer'] = true; } else { $settings_values['numberedAnswer'] = false; } if ( ( isset( $settings_values['titleHidden'] ) ) && ( 'on' === $settings_values['titleHidden'] ) ) { $settings_values['titleHidden'] = false; } else { $settings_values['titleHidden'] = true; } if ( ( isset( $settings_values['quizModus'] ) ) && ( ! empty( $settings_values['quizModus'] ) ) ) { if ( 'single' === $settings_values['quizModus'] ) { $settings_values['quizModus_multiple_questionsPerPage'] = 0; $settings_values['quizModus'] = 0; if ( 'on' === $settings_values['quizModus_single_back_button'] ) { $settings_values['quizModus'] = 1; } if ( 'each' === $settings_values['quizModus_single_feedback'] ) { $settings_values['quizModus'] = 2; } } elseif ( 'multiple' === $settings_values['quizModus'] ) { $settings_values['quizModus'] = 3; if ( isset( $settings_values['quizModus_multiple_questionsPerPage'] ) ) { $settings_values['quizModus_multiple_questionsPerPage'] = absint( $settings_values['quizModus_multiple_questionsPerPage'] ); } } } if ( ( isset( $settings_values['custom_sorting'] ) ) && ( 'on' === $settings_values['custom_sorting'] ) ) { if ( ( isset( $settings_values['questionRandom'] ) ) && ( true === $settings_values['questionRandom'] ) ) { if ( ( isset( $settings_values['showMaxQuestion'] ) ) && ( true === $settings_values['showMaxQuestion'] ) ) { if ( ( isset( $settings_values['showMaxQuestionValue'] ) ) && ( ! empty( $settings_values['showMaxQuestionValue'] ) ) ) { $settings_values['showMaxQuestionValue'] = absint( $settings_values['showMaxQuestionValue'] ); } else { $settings_values['showMaxQuestion'] = ''; $settings_values['showMaxQuestionValue'] = 0; } } else { $settings_values['showMaxQuestion'] = ''; } } else { $settings_values['questionRandom'] = ''; } } else { $settings_values['custom_sorting'] = ''; $settings_values['questionRandom'] = ''; $settings_values['showMaxQuestion'] = ''; $settings_values['showMaxQuestionValue'] = ''; } } return $settings_values; } // End of functions. } add_filter( 'learndash_post_settings_metaboxes_init_' . learndash_get_post_type_slug( 'quiz' ), function( $metaboxes = array() ) { if ( ( ! isset( $metaboxes['LearnDash_Settings_Metabox_Quiz_Display_Content'] ) ) && ( class_exists( 'LearnDash_Settings_Metabox_Quiz_Display_Content' ) ) ) { $metaboxes['LearnDash_Settings_Metabox_Quiz_Display_Content'] = LearnDash_Settings_Metabox_Quiz_Display_Content::add_metabox_instance(); } return $metaboxes; }, 50, 1 ); } settings-metaboxes/class-ld-settings-metabox-quiz-results-display-content-options.php 0000666 00000057750 15214240575 0025417 0 ustar 00 settings_screen_id = 'sfwd-quiz'; // Used within the Settings API to uniquely identify this section. $this->settings_metabox_key = 'learndash-quiz-results-options'; // Section label/header. $this->settings_section_label = esc_html__( 'Results Page Display', 'learndash' ); $this->settings_section_description = esc_html__( 'Controls how the results page will look', 'learndash' ); add_filter( 'learndash_metabox_save_fields_' . $this->settings_metabox_key, array( $this, 'filter_saved_fields' ), 30, 3 ); // Map internal settings field ID to legacy field ID. $this->settings_fields_map = array( 'resultGradeEnabled' => 'resultGradeEnabled', 'resultText' => 'resultText', 'resultTextGrade' => 'resultTextGrade', 'btnRestartQuizHidden' => 'btnRestartQuizHidden', 'showAverageResult' => 'showAverageResult', 'showCategoryScore' => 'showCategoryScore', 'hideResultPoints' => 'hideResultPoints', 'hideResultCorrectQuestion' => 'hideResultCorrectQuestion', 'hideResultQuizTime' => 'hideResultQuizTime', 'hideAnswerMessageBox' => 'hideAnswerMessageBox', 'disabledAnswerMark' => 'disabledAnswerMark', 'btnViewQuestionHidden' => 'btnViewQuestionHidden', 'custom_answer_feedback' => 'custom_answer_feedback', ); parent::__construct(); } public function save_fields_to_post( $pro_quiz_edit, $settings_values = array() ) { $_POST['resultGradeEnabled'] = $settings_values['resultGradeEnabled']; $_POST['btnRestartQuizHidden'] = $settings_values['btnRestartQuizHidden']; $_POST['showAverageResult'] = $settings_values['showAverageResult']; $_POST['showCategoryScore'] = $settings_values['showCategoryScore']; $_POST['hideResultPoints'] = $settings_values['hideResultPoints']; $_POST['hideResultCorrectQuestion'] = $settings_values['hideResultCorrectQuestion']; $_POST['hideResultQuizTime'] = $settings_values['hideResultQuizTime']; $_POST['hideAnswerMessageBox'] = $settings_values['hideAnswerMessageBox']; $_POST['disabledAnswerMark'] = $settings_values['disabledAnswerMark']; $_POST['btnViewQuestionHidden'] = $settings_values['btnViewQuestionHidden']; } /** * Initialize the metabox settings values. */ public function load_settings_values() { parent::load_settings_values(); $this->quiz_edit = $this->init_quiz_edit( $this->_post ); if ( true === $this->settings_values_loaded ) { if ( $this->quiz_edit['quiz'] ) { $this->setting_option_values['resultGradeEnabled'] = $this->quiz_edit['quiz']->isResultGradeEnabled(); if ( true === $this->setting_option_values['resultGradeEnabled'] ) { $this->setting_option_values['resultGradeEnabled'] = true; } else { $this->setting_option_values['resultGradeEnabled'] = ''; } // Always enabled. //$this->setting_option_values['resultGradeEnabled'] = true; $this->setting_option_values['btnRestartQuizHidden'] = $this->quiz_edit['quiz']->isBtnRestartQuizHidden(); if ( true !== $this->setting_option_values['btnRestartQuizHidden'] ) { $this->setting_option_values['btnRestartQuizHidden'] = 'on'; } else { $this->setting_option_values['btnRestartQuizHidden'] = ''; } $this->setting_option_values['showAverageResult'] = $this->quiz_edit['quiz']->isShowAverageResult(); if ( true === $this->setting_option_values['showAverageResult'] ) { $this->setting_option_values['showAverageResult'] = 'on'; } else { $this->setting_option_values['showAverageResult'] = ''; } $this->setting_option_values['showCategoryScore'] = $this->quiz_edit['quiz']->isShowCategoryScore(); if ( true === $this->setting_option_values['showCategoryScore'] ) { $this->setting_option_values['showCategoryScore'] = 'on'; } else { $this->setting_option_values['showCategoryScore'] = ''; } $this->setting_option_values['hideResultPoints'] = $this->quiz_edit['quiz']->isHideResultPoints(); if ( true !== $this->setting_option_values['hideResultPoints'] ) { $this->setting_option_values['hideResultPoints'] = 'on'; } else { $this->setting_option_values['hideResultPoints'] = ''; } $this->setting_option_values['hideResultCorrectQuestion'] = $this->quiz_edit['quiz']->isHideResultCorrectQuestion(); if ( true !== $this->setting_option_values['hideResultCorrectQuestion'] ) { $this->setting_option_values['hideResultCorrectQuestion'] = 'on'; } else { $this->setting_option_values['hideResultCorrectQuestion'] = ''; } $this->setting_option_values['hideResultQuizTime'] = $this->quiz_edit['quiz']->isHideResultQuizTime(); if ( true !== $this->setting_option_values['hideResultQuizTime'] ) { $this->setting_option_values['hideResultQuizTime'] = 'on'; } else { $this->setting_option_values['hideResultQuizTime'] = ''; } if ( ( 'on' === $this->setting_option_values['showAverageResult'] ) || ( 'on' === $this->setting_option_values['showCategoryScore'] ) || ( 'on' === $this->setting_option_values['hideResultPoints'] ) || ( 'on' === $this->setting_option_values['hideResultCorrectQuestion'] ) || ( 'on' === $this->setting_option_values['hideResultQuizTime'] ) ) { $this->setting_option_values['custom_result_data_display'] = 'on'; } else { $this->setting_option_values['custom_result_data_display'] = ''; } $this->setting_option_values['hideAnswerMessageBox'] = $this->quiz_edit['quiz']->isHideAnswerMessageBox(); if ( true !== $this->setting_option_values['hideAnswerMessageBox'] ) { $this->setting_option_values['hideAnswerMessageBox'] = 'on'; } else { $this->setting_option_values['hideAnswerMessageBox'] = ''; } $this->setting_option_values['disabledAnswerMark'] = $this->quiz_edit['quiz']->isDisabledAnswerMark(); if ( true !== $this->setting_option_values['disabledAnswerMark'] ) { $this->setting_option_values['disabledAnswerMark'] = 'on'; } else { $this->setting_option_values['disabledAnswerMark'] = ''; } $this->setting_option_values['btnViewQuestionHidden'] = $this->quiz_edit['quiz']->isBtnViewQuestionHidden(); if ( true !== $this->setting_option_values['btnViewQuestionHidden'] ) { $this->setting_option_values['btnViewQuestionHidden'] = 'on'; } else { $this->setting_option_values['btnViewQuestionHidden'] = ''; } if ( ( 'on' === $this->setting_option_values['hideAnswerMessageBox'] ) || ( 'on' === $this->setting_option_values['disabledAnswerMark'] ) || ( 'on' === $this->setting_option_values['btnViewQuestionHidden'] ) ) { $this->setting_option_values['custom_answer_feedback'] = 'on'; } else { $this->setting_option_values['custom_answer_feedback'] = ''; } $this->setting_option_values['resultTextGrade'] = array(); $this->setting_option_values['resultText'] = $this->quiz_edit['quiz']->getResultText(); if ( ( '' === $this->setting_option_values['resultText'] ) || ( isset ( $this->setting_option_values['resultText']['text'][0] ) ) && ( ! empty( $this->setting_option_values['resultText']['text'][0] ) ) ) { $this->setting_option_values['resultGradeEnabled'] = 'on'; if ( is_array( $this->setting_option_values['resultText'] ) ) { $this->setting_option_values['resultTextGrade'] = $this->setting_option_values['resultText']; } else { $this->setting_option_values['resultTextGrade']['text'][0] = $this->setting_option_values['resultText']; $this->setting_option_values['resultTextGrade']['prozent'][0] = '0'; $this->setting_option_values['resultTextGrade']['activ'][0] = '1'; } } else { $this->setting_option_values['resultGradeEnabled'] = ''; } } } foreach ( $this->settings_fields_map as $_internal => $_external ) { if ( ! isset( $this->setting_option_values[ $_internal ] ) ) { $this->setting_option_values[ $_internal ] = ''; } } } /** * Initialize the metabox settings fields. */ public function load_settings_fields() { global $sfwd_lms; $this->setting_option_fields = array( 'resultGradeEnabled' => array( 'name' => 'resultGradeEnabled', 'type' => 'checkbox-switch', 'label' => esc_html__( 'Result Message(s)', 'learndash' ), 'value' => $this->setting_option_values['resultGradeEnabled'], 'default' => '', 'help_text' => esc_html__( "When enabled, the first message will be diplayed to ALL users. To customize the message based on earned score, add new Graduation Levels and set the 'From' field to the desired grade.", 'learndash' ), 'options' => array( '' => '', 'on' => sprintf( // translators: placeholder: Quiz. esc_html_x( 'The message below is displayed on the %s results page.', 'placeholder: Quiz', 'learndash' ), learndash_get_custom_label( 'Quiz' ) ), ), 'child_section_state' => ( 'on' === $this->setting_option_values['resultGradeEnabled'] ) ? 'open' : 'closed', ), 'resultText' => array( 'name' => 'resultText', 'type' => 'custom', 'label_none' => true, 'input_full' => true, 'parent_setting' => 'resultGradeEnabled', 'html' => $this->get_custom_result_messages(), ), 'btnRestartQuizHidden' => array( 'name' => 'btnRestartQuizHidden', 'type' => 'checkbox-switch', 'label' => sprintf( // translators: placeholder: Quiz. esc_html_x( 'Restart %s button', 'placeholder: Quiz', 'learndash' ), learndash_get_custom_label( 'Quiz' ) ), 'value' => $this->setting_option_values['btnRestartQuizHidden'], 'default' => 'on', 'options' => array( 'on' => '', ), ), 'custom_result_data_display' => array( 'name' => 'custom_result_data_display', 'type' => 'checkbox-switch', 'label' => esc_html__( 'Custom Results Display', 'learndash' ), 'value' => $this->setting_option_values['custom_result_data_display'], 'default' => 'on', 'options' => array( '' => '', 'on' => esc_html__( 'Enable the items you wish to display on the Result Page', 'learndash' ), ), 'child_section_state' => ( 'on' === $this->setting_option_values['custom_result_data_display'] ) ? 'open' : 'closed', ), 'showAverageResult' => array( 'name' => 'showAverageResult', 'type' => 'checkbox-switch', 'label' => esc_html__( 'Average Score', 'learndash' ), 'help_text' => sprintf( // translators: placeholder: quiz. esc_html_x( 'Display the average score of all users who took the %s', 'placeholder: quiz', 'learndash' ), learndash_get_custom_label_lower( 'quiz' ) ), 'value' => $this->setting_option_values['showAverageResult'], 'default' => 'on', 'options' => array( 'on' => '', ), 'parent_setting' => 'custom_result_data_display', ), 'showCategoryScore' => array( 'name' => 'showCategoryScore', 'type' => 'checkbox-switch', 'label' => esc_html__( 'Category Score', 'learndash' ), 'help_text' => sprintf( // translators: placeholder: Question. esc_html_x( 'Display the score achieved for each %s Category', 'placeholder: Question', 'learndash' ), learndash_get_custom_label( 'question' ) ), 'value' => $this->setting_option_values['showCategoryScore'], 'default' => 'on', 'options' => array( 'on' => '', ), 'parent_setting' => 'custom_result_data_display', ), 'hideResultPoints' => array( 'name' => 'hideResultPoints', 'type' => 'checkbox-switch', 'label' => esc_html__( 'Overall Score', 'learndash' ), 'parent_setting' => 'custom_result_data_display', 'value' => $this->setting_option_values['hideResultPoints'], 'default' => 'on', 'options' => array( 'on' => '', '' => sprintf( // translators: placeholder: Quiz. esc_html_x( 'The achieved %s score is NOT be displayed on the Results page', 'placeholder: Quiz', 'learndash' ), learndash_get_custom_label( 'quiz' ) ), ), ), 'hideResultCorrectQuestion' => array( 'name' => 'hideResultCorrectQuestion', 'type' => 'checkbox-switch', 'label' => esc_html__( 'No. of Correct Answers', 'learndash' ), 'parent_setting' => 'custom_result_data_display', 'value' => $this->setting_option_values['hideResultCorrectQuestion'], 'default' => 'on', 'options' => array( 'on' => '', '' => sprintf( // translators: placeholder: Questions. esc_html_x( 'The number of correctly answered %s is NOT displayed on the Results page.', 'placeholder: Questions', 'learndash' ), learndash_get_custom_label( 'questions' ) ), ), ), 'hideResultQuizTime' => array( 'name' => 'hideResultQuizTime', 'type' => 'checkbox-switch', 'label' => esc_html__( 'Time Spent', 'learndash' ), 'parent_setting' => 'custom_result_data_display', 'value' => $this->setting_option_values['hideResultQuizTime'], 'default' => 'on', 'options' => array( 'on' => '', ), ), 'custom_answer_feedback' => array( 'name' => 'custom_answer_feedback', 'type' => 'checkbox-switch', 'label' => esc_html__( 'Custom Answer Feedback', 'learndash' ), 'help_text' => sprintf( // translators: placeholder: questions. esc_html_x( 'Select which data users should be able to view when reviewing their submitted %s.', 'placeholder: questions', 'learndash' ), learndash_get_custom_label_lower( 'questions' ) ), 'value' => $this->setting_option_values['custom_answer_feedback'], 'default' => 'on', 'options' => array( 'on' => '', ), 'child_section_state' => ( 'on' === $this->setting_option_values['custom_answer_feedback'] ) ? 'open' : 'closed', ), 'hideAnswerMessageBox' => array( 'name' => 'hideAnswerMessageBox', 'type' => 'checkbox-switch', 'label' => esc_html__( 'Correct / Incorrect Messages', 'learndash' ), 'value' => $this->setting_option_values['hideAnswerMessageBox'], 'default' => 'on', 'options' => array( 'on' => '', ), 'parent_setting' => 'custom_answer_feedback', ), 'disabledAnswerMark' => array( 'name' => 'disabledAnswerMark', 'type' => 'checkbox-switch', 'label' => esc_html__( 'Correct / Incorrect Answer Marks', 'learndash' ), 'value' => $this->setting_option_values['disabledAnswerMark'], 'default' => 'on', 'options' => array( 'on' => '', ), 'parent_setting' => 'custom_answer_feedback', ), 'btnViewQuestionHidden' => array( 'name' => 'btnViewQuestionHidden', 'type' => 'checkbox-switch', 'label' => sprintf( // translators: placeholder: Questions. esc_html_x( 'View %s Button', 'placeholder: Questions', 'learndash' ), learndash_get_custom_label( 'questions' ) ), 'value' => $this->setting_option_values['btnViewQuestionHidden'], 'default' => 'on', 'options' => array( 'on' => '', ), 'parent_setting' => 'custom_answer_feedback', ), ); $this->setting_option_fields = apply_filters( 'learndash_settings_fields', $this->setting_option_fields, $this->settings_metabox_key ); parent::load_settings_fields(); } /** * Filter settings values for metabox before save to database. * * @param array $settings_values Array of settings values. * @param string $settings_metabox_key Metabox key. * @param string $settings_screen_id Screen ID. * @return array $settings_values. */ public function filter_saved_fields( $settings_values = array(), $settings_metabox_key = '', $settings_screen_id = '' ) { if ( ( $settings_screen_id === $this->settings_screen_id ) && ( $settings_metabox_key === $this->settings_metabox_key ) ) { if ( ( isset( $settings_values['resultGradeEnabled'] ) ) && ( 'on' === $settings_values['resultGradeEnabled'] ) ) { $settings_values['resultGradeEnabled'] = true; } else { $settings_values['resultGradeEnabled'] = false; } //if ( isset( $_POST['resultTextGrade'] ) ) { // if ( ( isset( $_POST['resultTextGrade']['text'][0] ) ) && ( ! empty( $_POST['resultTextGrade']['text'][0] ) ) ) { // $settings_values['btnRestartQuizHidden'] = true; // } //} if ( ( ! isset( $settings_values['btnRestartQuizHidden'] ) ) || ( 'on' === $settings_values['btnRestartQuizHidden'] ) ) { $settings_values['btnRestartQuizHidden'] = false; } else { $settings_values['btnRestartQuizHidden'] = true; } if ( ! isset( $settings_values['showAverageResult'] ) ) { $settings_values['showAverageResult'] = ''; } if ( ! isset( $settings_values['showCategoryScore'] ) ) { $settings_values['showCategoryScore'] = ''; } if ( ( ! isset( $settings_values['hideResultPoints'] ) ) || ( 'on' === $settings_values['hideResultPoints'] ) ) { $settings_values['hideResultPoints'] = false; } else { $settings_values['hideResultPoints'] = true; } if ( ( ! isset( $settings_values['hideResultCorrectQuestion'] ) ) || ( 'on' === $settings_values['hideResultCorrectQuestion'] ) ) { $settings_values['hideResultCorrectQuestion'] = false; } else { $settings_values['hideResultCorrectQuestion'] = true; } if ( ( ! isset( $settings_values['hideResultQuizTime'] ) ) || ( 'on' === $settings_values['hideResultQuizTime'] ) ) { $settings_values['hideResultQuizTime'] = false; } else { $settings_values['hideResultQuizTime'] = true; } if ( ( ! isset( $settings_values['hideAnswerMessageBox'] ) ) || ( 'on' === $settings_values['hideAnswerMessageBox'] ) ) { $settings_values['hideAnswerMessageBox'] = false; } else { $settings_values['hideAnswerMessageBox'] = true; } if ( ( ! isset( $settings_values['disabledAnswerMark'] ) ) || ( 'on' === $settings_values['disabledAnswerMark'] ) ) { $settings_values['disabledAnswerMark'] = false; } else { $settings_values['disabledAnswerMark'] = true; } if ( ( ! isset( $settings_values['btnViewQuestionHidden'] ) ) || ( 'on' === $settings_values['btnViewQuestionHidden'] ) ) { $settings_values['btnViewQuestionHidden'] = false; } else { $settings_values['btnViewQuestionHidden'] = true; } if ( ! isset( $settings_values['custom_answer_feedback'] ) ) { $settings_values['custom_answer_feedback'] = ''; } if ( '' === $settings_values['custom_answer_feedback'] ) { $settings_values['hideAnswerMessageBox'] = true; $settings_values['disabledAnswerMark'] = true; $settings_values['btnViewQuestionHidden'] = true; } if ( ! isset( $settings_values['custom_result_data_display'] ) ) { $settings_values['custom_result_data_display'] = ''; } } return $settings_values; } public function get_custom_result_messages() { $result_text = $this->setting_option_values['resultText']; $html = ''; $level = ob_get_level(); ob_start(); ?>
| ' . esc_html__( 'Move', 'learndash' ) . ' | ' . esc_html__( 'ID', 'learndash' ) . ' | ' . esc_html__( 'Field name', 'learndash' ) . ' | ' . esc_html__( 'Type', 'learndash' ) . ' | ' . esc_html__( 'Required?', 'learndash' ) . ' | |
|---|---|---|---|---|---|
| ' . esc_attr( $form_id ) . ' | '; $html .= ''; $html .= ' | '; $html .= '';
$html .= ' |
isRequired(), 1, false ) . '>
|
'. print_r($setting_option_field, true) .''); } $field_instance = LearnDash_Settings_Fields::get_field_instance( $setting_option_field['type'] ); if ( ( $field_instance ) && ( 'LearnDash_Settings_Fields' === get_parent_class( $field_instance ) ) ) { $setting_option_field['setting_option_key'] = $this->setting_option_key; if ( ! isset( $setting_option_field['id'] ) ) { $setting_option_field['id'] = $setting_option_field['setting_option_key'] . '_' . $setting_option_field['name']; } if ( ! isset( $setting_option_field['label_for'] ) ) { $setting_option_field['label_for'] = $setting_option_field['id']; } if ( ! isset( $setting_option_field['name_wrap'] ) ) { $setting_option_field['name_wrap'] = true; } if ( ! isset( $setting_option_field['input_show'] ) ) { $setting_option_field['input_show'] = true; } if ( ! isset( $setting_option_field['display_callback'] ) ) { $display_ref = LearnDash_Settings_Fields::get_field_instance( $setting_option_field['type'] )->get_creation_function_ref(); if ( $display_ref ) { $setting_option_field['display_callback'] = $display_ref; } } if ( ( ! isset( $setting_option_field['value_type'] ) ) || ( empty( $setting_option_field['value_type'] ) ) ) { $setting_option_field['value_type'] = 'sanitize_text_field'; } if ( ! is_callable( $setting_option_field['value_type'] ) ) { $setting_option_field['value_type'] = 'sanitize_text_field'; } if ( ! isset( $setting_option_field['validate_callback'] ) ) { $validate_ref = LearnDash_Settings_Fields::get_field_instance( $setting_option_field['type'] )->get_validation_function_ref(); if ( $validate_ref ) { $setting_option_field['validate_callback'] = $validate_ref; } } if ( ! isset( $setting_option_field['value_callback'] ) ) { $value_ref = LearnDash_Settings_Fields::get_field_instance( $setting_option_field['type'] )->get_value_function_ref(); if ( $value_ref ) { $setting_option_field['value_callback'] = $value_ref; } } } } } /** * Save Section Settings values */ public function save_settings_values() { $this->settings_values_loaded = false; update_option( $this->setting_option_key, $this->setting_option_values ); } /** * Initialize the Settings page. * * @param string $settings_page_id ID of page being initialized. */ public function settings_page_init( $settings_page_id = '' ) { // Ensure settings_page_id is not empty and that it matches the page_id we want to display this section on. if ( ( ! empty( $settings_page_id ) ) && ( $settings_page_id === $this->settings_page_id ) && ( ! empty( $this->setting_option_fields ) ) ) { add_settings_section( $this->settings_section_key, $this->settings_section_label, array( $this, 'show_settings_section_description' ), $this->settings_page_id ); foreach ( $this->setting_option_fields as $setting_option_field ) { if ( ! isset( $setting_option_field['name'] ) ) { continue; } add_settings_field( $setting_option_field['name'], $setting_option_field['label'], $setting_option_field['display_callback'], $this->settings_page_id, $this->settings_section_key, $setting_option_field ); } register_setting( $this->settings_page_id, $this->setting_option_key, array( $this, 'settings_section_fields_validate' ) ); } } /** * Show Settings Section Description */ public function show_settings_section_description() { if ( ! empty( $this->settings_section_description ) ) { echo ''; } } /** * Output Settings Section nonce field. */ public function show_settings_section_nonce_field() { wp_nonce_field( $this->setting_option_key, $this->setting_option_key . '_nonce' ); } /** * Intercept the WP options save logic and check that we have a valid nonce. * * @since 3.0 * @param array $value Array of section fields values. * @param array $old_value Array of old values. * @param string $section_key Section option key should match $this->setting_option_key. */ public function section_pre_update_option( $value, $old_value, $section_key = '' ) { if ( ( empty( $section_key ) ) || ( $section_key !== $this->setting_option_key ) ) { return $old_value; } if ( ! $this->verify_metabox_nonce_field() ) { $old_value; } return $value; } /** * Called AFTER section settings are update. * * @since 3.0 * @param array $value Array of section fields values. * @param array $old_value Array of old values. * @param string $section_key Section option key should match $this->setting_option_key. */ public function section_update_option( $old_value = '', $value = '', $section_key = '' ) { if ( ( ! empty( $section_key ) ) && ( $section_key === $this->setting_option_key ) ) { // When a section values change we update our internal set and also trigger reload fresh. if ( ! defined( 'LEARNDASH_SETTINGS_UPDATING' ) ) { define( 'LEARNDASH_SETTINGS_UPDATING', true ); } $this->setting_option_values = $value; $this->settings_values_loaded = false; $this->settings_fields_loaded = false; return true; } } /** * Verify Settings Section nonce field POST value. */ public function verify_metabox_nonce_field() { if ( ( isset( $_POST[ $this->setting_option_key . '_nonce' ] ) ) && ( ! empty( $_POST[ $this->setting_option_key . '_nonce' ] ) ) && ( wp_verify_nonce( esc_attr( $_POST[ $this->setting_option_key . '_nonce' ] ), $this->setting_option_key ) ) ) { return true; } } /** * Show Settings Section reset link */ public function show_settings_section_reset_confirm_link() { if ( ! empty( $this->reset_confirm_message ) ) { $reset_url = add_query_arg( array( 'action' => 'ld_reset_settings', 'ld_wpnonce' => wp_create_nonce( get_current_user_id() . '-' . $this->setting_option_key ), ) ); ?> settings_screen_id ) { if ( apply_filters( 'learndash_show_metabox', true, $this->metabox_key, $this->settings_screen_id ) ) { if ( ! isset( $learndash_metaboxes[ $this->settings_screen_id ] ) ) { $learndash_metaboxes[ $this->settings_screen_id ] = array(); } $learndash_metaboxes[ $this->settings_screen_id ][ $this->metabox_key ] = $this->metabox_key; add_meta_box( $this->metabox_key, $this->settings_section_label, array( $this, 'show_meta_box' ), $this->settings_screen_id, $this->metabox_context, $this->metabox_priority ); } } } /** * Show Settings Section meta box. */ public function show_meta_box() { global $wp_settings_sections; $this->show_settings_section_nonce_field(); if ( isset( $wp_settings_sections[ $this->settings_page_id ][ $this->settings_section_key ] ) ) { $this->show_settings_section( $wp_settings_sections[ $this->settings_page_id ][ $this->settings_section_key ] ); } else { $this->show_settings_section(); } } /** * Show the meta box settings * * @param string $section Section to be shown. */ public function show_settings_section( $section = null ) { /** * The 'callback' attribute is set if/when the section description is * to be displayed. See the WP add_settings_section() argument #3. */ if ( ( ! is_null( $section ) ) && ( isset( $section['callback'] ) ) && ( ! empty( $section['callback'] ) ) && ( is_callable( $section['callback'] ) ) ) { call_user_func( $section['callback'] ); } // If this section defined its own display callback logic. if ( ( isset( $this->settings_fields_callback ) ) && ( ! empty( $this->settings_fields_callback ) ) && ( is_callable( $this->settings_fields_callback ) ) ) { call_user_func( $this->settings_fields_callback, $this->settings_page_id, $this->settings_section_key ); } else { /** * Note here we are calling a custom version of the WP function * do_settings_fields because we want to control the label and help icons */ do_action( 'learndash_section_before', $this->settings_section_key, $this->settings_screen_id ); echo ''; do_action( 'learndash_section_after', $this->settings_section_key, $this->settings_screen_id ); } } /** * Show Settings Section Fields. * * @param string $page Page shown. * @param string $section Section shown. */ public function show_settings_section_fields( $page, $section ) { global $wp_settings_fields; if ( ! isset( $wp_settings_fields[ $page ][ $section ] ) ) { return; } LearnDash_Settings_Fields::show_section_fields( $wp_settings_fields[ $page ][ $section ] ); } /** * This validation function is set via the call to 'register_setting' * and will be called for each section. * * @param array $post_fields Array of section fields. */ public function settings_section_fields_validate( $post_fields = array() ) { $setting_option_values = array(); // This valiadate_args array will be passed to the validation function for context. $validate_args = array( 'settings_page_id' => $this->settings_page_id, 'setting_option_key' => $this->setting_option_key, 'post_fields' => $post_fields, 'field' => null, ); if ( ! empty( $post_fields ) ) { foreach ( $post_fields as $key => $val ) { if ( isset( $this->setting_option_fields[ $key ] ) ) { if ( ( isset( $this->setting_option_fields[ $key ]['validate_callback'] ) ) && ( ! empty( $this->setting_option_fields[ $key ]['validate_callback'] ) ) && ( is_callable( $this->setting_option_fields[ $key ]['validate_callback'] ) ) ) { $validate_args['field'] = $this->setting_option_fields[ $key ]; $setting_option_values[ $key ] = call_user_func( $this->setting_option_fields[ $key ]['validate_callback'], $val, $key, $validate_args ); } } } } return $setting_option_values; } /** * Static function to get section setting. * * @param string $field_key Section field key. * @param mixed $default_return Default value if field not found. */ public static function get_setting( $field_key = '', $default_return = '' ) { return self::get_section_setting( get_called_class(), $field_key, $default_return ); } /** * Static function to get all section settings. */ public static function get_settings_all() { return self::get_section_settings_all( get_called_class() ); } /** * Static function to get section to get option label. * * @param string $field_key Section field key. * @param string $option_key Section option key. */ public static function get_setting_select_option_label( $field_key = '', $option_key = '' ) { return self::get_section_setting_select_option_label( get_called_class(), $field_key, $option_key ); } /** * Static function to get a Section Setting value. * * @param string $section Settings Section. * @param string $field_key Settings Section field key. * @param mixed $default_return Default value if field not found. */ public static function get_section_setting( $section = '', $field_key = '', $default_return = '' ) { if ( empty( $section ) ) { $section = get_called_class(); } $field_key = self::check_deprecated_field_key( $field_key, $section ); $section = self::check_deprecated_class( $section ); if ( isset( self::$_instances[ $section ] ) ) { self::$_instances[ $section ]->init(); if ( isset( self::$_instances[ $section ]->setting_option_fields[ $field_key ] ) ) { $default_return = self::$_instances[ $section ]->setting_option_fields[ $field_key ]['value']; } } return $default_return; } /** * Static function to set a Section Setting value. * * @param string $section Settings Section. * @param string $field_key Settings Section field key. * @param mixed $new_value new value for field. */ public static function set_section_setting( $section = '', $field_key = '', $new_value = '' ) { if ( ( ! empty( $section ) ) && ( ! empty( $field_key ) ) ) { $field_key = self::check_deprecated_field_key( $field_key, $section ); $section = self::check_deprecated_class( $section ); if ( isset( self::$_instances[ $section ] ) ) { self::$_instances[ $section ]->init(); if ( isset( self::$_instances[ $section ]->setting_option_fields[ $field_key ] ) ) { self::$_instances[ $section ]->setting_option_fields[ $field_key ]['value'] = $new_value; self::$_instances[ $section ]->save_settings_values(); } } } } /** * Static function to get all Section fields. * * @param string $section Settings Section. * @param string $field Settings Section field key. */ public static function get_section_settings_all( $section_org = '', $field = 'value' ) { if ( empty( $section_org ) ) { $section_org = get_called_class(); } $section = self::check_deprecated_class( $section_org ); if ( empty( $section ) ) { $section = $section_org; } if ( isset( self::$_instances[ $section ] ) ) { self::$_instances[ $section ]->init(); $fields_values = wp_list_pluck( self::$_instances[ $section ]->setting_option_fields, $field ); // If we are dealing with deprecated values we provide the old key/value sets as well so easy the logic on the caller. if ( $section_org !== $section ) { if ( ( isset( self::$_settings_deprecated[ $section_org ]['fields'] ) ) && ( ! empty( self::$_settings_deprecated[ $section_org ]['fields'] ) ) ) { foreach ( self::$_settings_deprecated[ $section_org ]['fields'] as $old_field => $new_field ) { if ( ( ! isset( $fields_values[ $old_field ] ) ) && ( isset( self::$_instances[ $section ]->setting_option_values[ $new_field ][ $field ] ) ) ) { $fields_values[ $old_field ] = self::$_instances[ $section ]->setting_option_fields[ $new_field ][ $field ]; } elseif ( ( 'value' === $field ) && ( isset( self::$_instances[ $section ]->setting_option_values[ $new_field ] ) ) ) { $fields_values[ $old_field ] = self::$_instances[ $section ]->setting_option_values[ $new_field ]; } } } } return $fields_values; } } /** * From a section settings you can access the label used on a select by the option key. * * @param string $section Settings Section. * @param string $field_key Settings Section field key. * @param string $option_key Option key. */ public static function get_section_setting_select_option_label( $section = '', $field_key = '', $option_key = '' ) { if ( empty( $section ) ) { $section = get_called_class(); } if ( ! empty( $field_key ) ) { $field_key = self::check_deprecated_field_key( $field_key, $section ); $section = self::check_deprecated_class( $section ); if ( isset( self::$_instances[ $section ] ) ) { self::$_instances[ $section ]->init(); // If the option_key was not passed we default to the current selected value. if ( empty( $option_key ) ) { $option_key = self::$_instances[ $section ]->get_setting( $field_key ); } // Now we get the option fields by the field_key and then derive the option label from the option_key. if ( ( isset( self::$_instances[ $section ]->setting_option_fields[ $field_key ] ) ) && ( 'select' === self::$_instances[ $section ]->setting_option_fields[ $field_key ]['type'] ) && ( self::$_instances[ $section ]->setting_option_fields[ $field_key ]['options'] ) && ( isset( self::$_instances[ $section ]->setting_option_fields[ $field_key ]['options'][ $option_key ] ) ) ) { return self::$_instances[ $section ]->setting_option_fields[ $field_key ]['options'][ $option_key ]; } } } } /** * Transition settings from old class into current one. * * @since 3.0 */ public function transition_deprecated_settings() { if ( ! empty( $this->settings_deprecated ) ) { foreach ( $this->settings_deprecated as $old_class => $old_class_settings ) { if ( ( isset( $old_class_settings['option_key'] ) ) && ( ! empty( $old_class_settings['option_key'] ) ) ) { $old_settings_values = get_option( $old_class_settings['option_key'] ); if ( ( isset( $old_class_settings['fields'] ) ) && ( ! empty( $old_class_settings['fields'] ) ) ) { foreach ( $old_class_settings['fields'] as $old_setting_key => $new_setting_key ) { if ( isset( $old_settings_values[ $old_setting_key ] ) ) { $this->setting_option_values[ $new_setting_key ] = $old_settings_values[ $old_setting_key ]; } } } } } } } /** * Transition old Settiings Class to new one. * * @since 3.0 * @param string $section Old section class. * @return string New section Class. */ public static function check_deprecated_class( $section = '' ) { if ( ! empty( $section ) ) { if ( isset( self::$_settings_deprecated[ $section ] ) ) { $section = self::$_settings_deprecated[ $section ]['class']; } } return $section; } /** * Transition old Settiings Class field(s) to new one(s). * * @since 3.0 * @param string $field_key Old section field key. * @param string $section Old section class. * @return string new field key. */ public static function check_deprecated_field_key( $field_key = '', $old_section = '' ) { if ( ( ! empty( $old_section ) ) && ( isset( self::$_settings_deprecated[ $old_section ] ) ) ) { if ( isset( self::$_settings_deprecated[ $old_section ]['fields'] ) ) { $section_fields = self::$_settings_deprecated[ $old_section ]['fields']; if ( ! empty( $section_fields ) ) { if ( isset( $section_fields[ $field_key ] ) ) { $field_key = $section_fields[ $field_key ]; } } } } return $field_key; } } } if ( ( class_exists( 'LearnDash_Settings_Section' ) ) && ( ! class_exists( 'LearnDash_Theme_Settings_Section' ) ) ) { /** * Class to create the settings section. */ abstract class LearnDash_Theme_Settings_Section extends LearnDash_Settings_Section { /** * Match Theme Key. * This should match the theme_key set within the LearnDash_Theme_Register instance. * * @var string $settings_theme_key Settings Theme ID. */ protected $settings_theme_key = ''; /** * Protected constructor for class */ protected function __construct() { parent::__construct(); if ( ! empty( $this->settings_theme_key ) ) { LearnDash_Theme_Register::register_theme_settings_section( $this->settings_theme_key, $this->settings_section_key, $this ); } add_filter( 'learndash_show_metabox', array( $this, 'learndash_show_metabox' ), 1, 3 ); } final public function learndash_show_metabox( $show_metabox = true, $metabox_key = '', $settings_screen_id = '' ) { if ( $metabox_key === $this->metabox_key ) { $show_metabox = false; } return $show_metabox; } } }