| 1 |
<?php |
| 2 |
namespace WPDeveloper\BetterDocs\Editors\Elementor; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; // Exit if accessed directly |
| 6 |
} |
| 7 |
|
| 8 |
use ElementorPro\Plugin; |
| 9 |
use Elementor\Controls_Manager; |
| 10 |
use ElementorPro\Modules\ThemeBuilder\Documents\Single_Base; |
| 11 |
|
| 12 |
/** |
| 13 |
* Working with elementor plugin |
| 14 |
* |
| 15 |
* |
| 16 |
* @since 1.3.0 |
| 17 |
* @package BetterDocs |
| 18 |
* @subpackage BetterDocs/elementor |
| 19 |
* @author WPDeveloper <support@wpdeveloper.com> |
| 20 |
*/ |
| 21 |
class SingleDocs extends Single_Base { |
| 22 |
public static function get_properties() { |
| 23 |
$properties = parent::get_properties(); |
| 24 |
|
| 25 |
$properties['location'] = 'single'; |
| 26 |
$properties['condition_type'] = 'docs'; |
| 27 |
|
| 28 |
return $properties; |
| 29 |
} |
| 30 |
|
| 31 |
protected static function get_site_editor_type() { |
| 32 |
return 'docs'; |
| 33 |
} |
| 34 |
|
| 35 |
public static function get_type() { |
| 36 |
return 'docs'; |
| 37 |
} |
| 38 |
|
| 39 |
public static function get_title() { |
| 40 |
return __( 'Single Doc', 'betterdocs' ); |
| 41 |
} |
| 42 |
|
| 43 |
public static function get_editor_panel_config() { |
| 44 |
$config = parent::get_editor_panel_config(); |
| 45 |
|
| 46 |
$config['widgets_settings']['betterdocs-elements'] = [ |
| 47 |
'show_in_panel' => true |
| 48 |
]; |
| 49 |
|
| 50 |
return $config; |
| 51 |
} |
| 52 |
|
| 53 |
public function get_depended_widget() { |
| 54 |
return Plugin::elementor()->widgets_manager->get_widget_types( 'betterdocs-content' ); |
| 55 |
} |
| 56 |
|
| 57 |
public function get_container_attributes() { |
| 58 |
$attributes = parent::get_container_attributes(); |
| 59 |
|
| 60 |
$attributes['class'] .= ' betterdocs'; |
| 61 |
|
| 62 |
return $attributes; |
| 63 |
} |
| 64 |
|
| 65 |
public function filter_body_classes( $body_classes ) { |
| 66 |
$body_classes = parent::filter_body_classes( $body_classes ); |
| 67 |
|
| 68 |
if ( get_the_ID() === $this->get_main_id() || Plugin::elementor()->preview->is_preview_mode( $this->get_main_id() ) ) { |
| 69 |
$body_classes[] = 'betterdocs-elementor-single'; |
| 70 |
} |
| 71 |
|
| 72 |
return $body_classes; |
| 73 |
} |
| 74 |
|
| 75 |
public function before_get_content() { |
| 76 |
parent::before_get_content(); |
| 77 |
|
| 78 |
do_action( 'betterdocs_before_single_product' ); |
| 79 |
} |
| 80 |
|
| 81 |
public function after_get_content() { |
| 82 |
parent::after_get_content(); |
| 83 |
|
| 84 |
do_action( 'betterdocs_after_single_product' ); |
| 85 |
} |
| 86 |
|
| 87 |
public function print_content() { |
| 88 |
if ( post_password_required() ) { |
| 89 |
echo get_the_password_form(); |
| 90 |
return; |
| 91 |
} |
| 92 |
|
| 93 |
parent::print_content(); |
| 94 |
} |
| 95 |
|
| 96 |
public function __construct( array $data = [] ) { |
| 97 |
parent::__construct( $data ); |
| 98 |
} |
| 99 |
|
| 100 |
protected static function get_editor_panel_categories() { |
| 101 |
$categories = [ |
| 102 |
// Move to top as active. |
| 103 |
'betterdocs-elements-single' => [ |
| 104 |
'title' => __( 'BetterDocs', 'betterdocs' ), |
| 105 |
'active' => true |
| 106 |
] |
| 107 |
]; |
| 108 |
|
| 109 |
$categories += parent::get_editor_panel_categories(); |
| 110 |
unset( $categories['theme-elements-single'] ); |
| 111 |
return $categories; |
| 112 |
} |
| 113 |
|
| 114 |
protected function register_controls() { |
| 115 |
parent::register_controls(); |
| 116 |
|
| 117 |
$this->update_control( |
| 118 |
'preview_type', |
| 119 |
[ |
| 120 |
'type' => Controls_Manager::HIDDEN, |
| 121 |
'default' => 'single/docs' |
| 122 |
] |
| 123 |
); |
| 124 |
|
| 125 |
$latest_posts = get_posts( [ |
| 126 |
'posts_per_page' => 1, |
| 127 |
'post_type' => 'docs' |
| 128 |
] ); |
| 129 |
|
| 130 |
if ( ! empty( $latest_posts ) ) { |
| 131 |
$this->update_control( |
| 132 |
'preview_id', |
| 133 |
[ |
| 134 |
'default' => $latest_posts[0]->ID |
| 135 |
] |
| 136 |
); |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
protected function get_remote_library_config() { |
| 141 |
$config = parent::get_remote_library_config(); |
| 142 |
|
| 143 |
$config['category'] = 'Single Docs'; |
| 144 |
|
| 145 |
return $config; |
| 146 |
} |
| 147 |
} |
| 148 |
|