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