get_name() || 'container' === $element->get_name() ) ) { $element->start_controls_section ( 'wpr_section_particles', [ 'tab' => Controls_Manager::TAB_STYLE, 'label' => sprintf(esc_html__('Particles - %s', 'wpr-addons'), Utilities::get_plugin_name()), ] ); $element->add_control( 'wpr_particles_apply_changes', [ 'type' => Controls_Manager::RAW_HTML, 'raw' => '
Update changes to Preview
', 'separator' => 'after' ] ); $element->add_control( 'particles_video_tutorial', [ 'raw' => '
Watch Video Tutorial ', 'type' => Controls_Manager::RAW_HTML, ] ); $element->add_control ( 'wpr_enable_particles', [ 'type' => Controls_Manager::SWITCHER, 'label' => esc_html__( 'Enable Particles Background', 'wpr-addons' ), 'default' => 'no', 'return_value' => 'yes', 'prefix_class' => 'wpr-particle-', 'render_type' => 'template', ] ); if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() ) { \WprAddonsPro\Extensions\Wpr_Particles_Pro::add_control_which_particle($element); } else { $element->add_control ( 'which_particle', [ 'label' => __( 'Select Style', 'plugin-domain' ), 'type' => Controls_Manager::SELECT, 'default' => 'wpr_particle_json_custom', 'options' => [ 'wpr_particle_json_custom' => __( 'Custom', 'plugin-domain' ), 'pro-pjs' => __( 'Predefined (Pro)', 'plugin-domain' ), ], 'condition' => [ 'wpr_enable_particles' => 'yes' ] ] ); // Upgrade to Pro Notice Utilities::upgrade_pro_notice( $element, Controls_Manager::RAW_HTML, 'particles', 'which_particle', ['pro-pjs'] ); } $this->custom_json_particles( $this->default_particles, $element ); if ( defined('WPR_ADDONS_PRO_VERSION') && wpr_fs()->can_use_premium_code() ) { \WprAddonsPro\Extensions\Wpr_Particles_Pro::add_control_group_predefined_particles($element); } $element->end_controls_section(); } // end if() } public function custom_json_particles($array, $element) { $element->add_control( 'wpr_particle_json_custom_notice', [ 'type' => Controls_Manager::RAW_HTML, 'content_classes' => 'elementor-control-field-description', 'raw' => __('Click here to generate JSON for the below field.', 'wpr-addons'), 'condition' => [ 'which_particle' => 'wpr_particle_json_custom', 'wpr_enable_particles' => 'yes' ], ] ); $element->add_control( 'wpr_particle_json_custom', [ 'type' => Controls_Manager::CODE, 'label' => esc_html__( 'Enter Custom JSON', 'wpr-addons' ), 'default' => $array, 'render_type' => 'template', 'condition' => [ 'which_particle' => 'wpr_particle_json_custom', 'wpr_enable_particles' => 'yes' ], ] ); } public function _print_template( $template, $widget ) { if ( $widget->get_name() !== 'section' && $widget->get_name() !== 'container' ) { return $template; } ob_start(); echo '
'; $particles_content = ob_get_contents(); ob_end_clean(); return $template . $particles_content; } public function _before_render( $element ) { if ( $element->get_name() !== 'section' && $element->get_name() !== 'container' ) { return; } $settings = $element->get_settings(); if ( $settings['wpr_enable_particles'] === 'yes' ) { $settings['which_particle'] = 'pro-pjs' === $settings['which_particle'] ? 'wpr_particle_json_custom' : $settings['which_particle']; if ( !defined('WPR_ADDONS_PRO_VERSION') || !wpr_fs()->can_use_premium_code() ) { $element->add_render_attribute( '_wrapper', [ 'data-wpr-particles' => $settings[$settings['which_particle']], 'particle-source' => $settings['which_particle'], ] ); } else { $element->add_render_attribute( '_wrapper', [ 'data-wpr-particles' => $settings[$settings['which_particle']], 'particle-source' => $settings['which_particle'], 'wpr-quantity' => $settings['quantity'], 'wpr-color' => $settings['particles_color'], 'wpr-speed' => $settings['particles_speed'], 'wpr-shape' => $settings['particles_shape'], 'wpr-size' => $settings['particles_size'] ] ); } } } public function enqueue_scripts() { wp_enqueue_script( 'wpr-particles', WPR_ADDONS_URL . 'assets/js/lib/particles/particles.js', [ 'jquery' ], '3.0.6', true ); } } new Wpr_Particles();