Completed
Push — staging ( e273cb...e4c251 )
by
unknown
13:50
created

YIKES_Easy_Form_Block::editor_scripts()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 47
rs 9.1563
c 0
b 0
f 0
1
<?php
2
/**
3
 * Class YIKES_Easy_Form.
4
 */
5
class YIKES_Easy_Form_Block extends YIKES_Easy_Forms_Blocks {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
6
7
	const BLOCK = 'easy-forms-block';
8
9
	/**
10
	 * Enqueue our scripts.
11
	 */
12
	public function editor_scripts() {
13
14
		// Localize the calendar.
15
		global $wp_locale;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
16
		$datepicker_options = array(
17
			'rtl'                 => $wp_locale->is_rtl(),
18
			'month_names'         => array_values( $wp_locale->month ),
19
			'month_names_short'   => array_values( $wp_locale->month_abbrev ),
20
			'day_names'           => array_values( $wp_locale->weekday ),
21
			'day_names_short'     => array_values( $wp_locale->weekday_abbrev ),
22
			'day_names_min'       => array_values( $wp_locale->weekday_initial ),
23
			'first_day'           => get_option( 'start_of_week' ),
24
			'change_month'        => false,
25
			'change_year'         => false,
26
			'min_date'            => null,
27
			'max_date'            => null,
28
			'default_date'        => null,
29
			'number_of_months'    => 1,
30
			'show_other_months'   => false,
31
			'select_other_months' => null,
32
			'show_anim'           => '',
33
			'show_button_panel'   => false,
34
		);
35
36
		wp_register_script( 'yikes-datepicker-scripts', YIKES_MC_URL . 'public/js/yikes-datepicker-scripts.min.js', array( 'jquery-ui-datepicker' ), YIKES_MC_VERSION, true );
37
		wp_localize_script( 'yikes-datepicker-scripts', 'datepicker_settings', $datepicker_options );
38
		wp_enqueue_script( 'yikes-datepicker-scripts' );
39
		wp_enqueue_style( 'jquery-datepicker-styles', YIKES_MC_URL . 'public/css/jquery-ui.min.css', array(), YIKES_MC_VERSION );
40
		wp_enqueue_style( 'yikes-datepicker-styles', YIKES_MC_URL . 'public/css/yikes-datepicker-styles.min.css', array(), YIKES_MC_VERSION );
41
42
		wp_register_script( 'yikes-easy-forms-blocks', YIKES_MC_URL . 'blocks/easy-forms-block/easy-forms-block.js', array( 'wp-i18n', 'wp-element', 'wp-blocks', 'wp-components', 'wp-api' ), filemtime( YIKES_MC_PATH . 'blocks/easy-forms-block/easy-forms-block.js' ), true );
43
		wp_localize_script( 'yikes-easy-forms-blocks', 'ez_forms_gb_data', array(
44
			'ajax_url'              => esc_url_raw( admin_url( 'admin-ajax.php' ) ),
45
			'fetch_form_nonce'      => wp_create_nonce( 'fetch_form_nonce' ),
46
			'fetch_forms_nonce'     => wp_create_nonce( 'fetch_forms_nonce' ),
47
			'fetch_recaptcha_nonce' => wp_create_nonce( 'fetch_recaptcha_nonce' ),
48
			'block_namespace'       => parent::BLOCK_NAMESPACE,
49
			'block_name'            => static::BLOCK,
50
		) );
51
		wp_enqueue_script( 'yikes-easy-forms-blocks' );
52
53
		wp_enqueue_script( 'yikes-google-recaptcha', 'https://www.google.com/recaptcha/api.js', array( 'jquery' ), YIKES_MC_VERSION, true );
54
55
		if ( ! defined( 'YIKES_MAILCHIMP_EXCLUDE_STYLES' ) ) {
56
			wp_enqueue_style( 'yikes-inc-easy-mailchimp-public-styles', YIKES_MC_URL . 'public/css/yikes-inc-easy-mailchimp-extender-public.min.css', array(), YIKES_MC_VERSION );
57
		}
58
	}
59
60
	/**
61
	 * Take the shortcode parameters from the Gutenberg block and render our shortcode.
62
	 *
63
	 * @param array  $attributes Block attributes.
64
	 * @param string $content    Block content.
65
	 */
66
	public function render_block( $attributes, $content ) {
67
68
		if ( ! isset( $attributes['form_id'] ) ) {
69
			return;
70
		}
71
72
		$shortcode_attributes = array(
73
			'form'                       => $attributes['form_id'],
74
			'submit'                     => isset( $attributes['submit_button_text'] ) && ! empty( $attributes['submit_button_text'] ) ? $attributes['submit_button_text'] : '',
75
			'title'                      => isset( $attributes['show_title'] ) && true === $attributes['show_title'] ? '1' : '0',
76
			'custom_title'               => isset( $attributes['form_title'] ) ? $attributes['form_title'] : '',
77
			'description'                => isset( $attributes['show_description'] ) && true === $attributes['show_description'] ? '1' : '0',
78
			'custom_description'         => isset( $attributes['form_description'] ) ? $attributes['form_description'] : '',
79
			'ajax'                       => isset( $attributes['is_ajax'] ) && true === $attributes['is_ajax'] ? '1' : '0',
80
			'recaptcha'                  => isset( $attributes['recaptcha'] ) && false === $attributes['recaptcha'] ? '0' : '',
81
			'recaptcha_lang'             => isset( $attributes['recaptcha_lang'] ) ? $attributes['recaptcha_lang'] : '',
82
			'recaptcha_type'             => isset( $attributes['recaptcha_type'] ) ? $attributes['recaptcha_type'] : '',
83
			'recaptcha_theme'            => isset( $attributes['recaptcha_theme'] ) ? $attributes['recaptcha_theme'] : '',
84
			'recaptcha_size'             => isset( $attributes['recaptcha_size'] ) ? $attributes['recaptcha_size'] : '',
85
			'recaptcha_data_callback'    => isset( $attributes['recaptcha_verify_callback'] ) ? $attributes['recaptcha_verify_callback'] : '',
86
			'recaptcha_expired_callback' => isset( $attributes['recaptcha_expired_callback'] ) ? $attributes['recaptcha_expired_callback'] : '',
87
			'inline'                     => isset( $attributes['inline'] ) && true === $attributes['inline'] ? '1' : '0',
88
		);
89
90
		// We want to run process_mailchimp_shortcode() but we need to return the plaintext shortcode or Gutenberg will autop() the shortcode content.
91
		return '[yikes-mailchimp form="' . $shortcode_attributes['form'] . '" submit="' . $shortcode_attributes['submit'] . '" title="' . $shortcode_attributes['title'] . '" custom_title="' . $shortcode_attributes['custom_title'] . '" description="' . $shortcode_attributes['description'] . '" custom_description="' . $shortcode_attributes['custom_description'] . '" ajax="' . $shortcode_attributes['ajax'] . '" recaptcha="' . $shortcode_attributes['recaptcha'] . '"  recaptcha_lang="' . $shortcode_attributes['recaptcha_lang'] . '" recaptcha_type="' . $shortcode_attributes['recaptcha_type'] . '" recaptcha_theme="' . $shortcode_attributes['recaptcha_theme'] . '" recaptcha_size="' . $shortcode_attributes['recaptcha_size'] . '" recaptcha_data_callback="' . $shortcode_attributes['recaptcha_data_callback'] . '" recaptcha_expired_callback="' . $shortcode_attributes['recaptcha_expired_callback'] . '" inline="' . $shortcode_attributes['inline'] . '"]';
92
	}
93
}
94