Elementor Pro: Adding Custom Display Conditions for Theme Builder


SUBMITTED BY: Guest

DATE: Jan. 19, 2024, 2:49 a.m.

FORMAT: PHP

SIZE: 902 Bytes

HITS: 419

  1. add_action( 'elementor/theme/register_conditions', function( $conditions_manager ) {
  2. class Page_Template_Condition extends ElementorPro\Modules\ThemeBuilder\Conditions\Condition_Base {
  3. public static function get_type() {
  4. return 'singular';
  5. }
  6. public static function get_priority() {
  7. return 30;
  8. }
  9. public function get_name() {
  10. return 'page_template';
  11. }
  12. public function get_label() {
  13. return __( 'Page Template' );
  14. }
  15. public function check( $args ) {
  16. return isset( $args['id'] ) && is_page_template( $args['id'] );
  17. }
  18. protected function _register_controls() {
  19. $this->add_control(
  20. 'page_template',
  21. [
  22. 'section' => 'settings',
  23. 'label' => __( 'Page Template' ),
  24. 'type' => \Elementor\Controls_Manager::SELECT,
  25. 'options' => array_flip( get_page_templates() ),
  26. ]
  27. );
  28. }
  29. }
  30. $conditions_manager->get_condition( 'singular' )->register_sub_condition( new Page_Template_Condition() );
  31. }, 100 );

comments powered by Disqus