@@ -18,13 +18,13 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class Wordlift_Admin_Select2_Element extends Wordlift_Admin_Select_Element { |
20 | 20 | |
21 | - /** |
|
22 | - * @inheritdoc |
|
23 | - */ |
|
24 | - public function render_options( $params ) { |
|
25 | - // Loop through all params and add the options. |
|
26 | - foreach ( $params['options'] as $value => $label ) : |
|
27 | - ?> |
|
21 | + /** |
|
22 | + * @inheritdoc |
|
23 | + */ |
|
24 | + public function render_options( $params ) { |
|
25 | + // Loop through all params and add the options. |
|
26 | + foreach ( $params['options'] as $value => $label ) : |
|
27 | + ?> |
|
28 | 28 | <option |
29 | 29 | value="<?php echo esc_attr( $value ); ?>" |
30 | 30 | <?php selected( $params['value'], $value ); ?> |
@@ -32,26 +32,26 @@ discard block |
||
32 | 32 | <?php echo esc_html( $label ); ?> |
33 | 33 | </option> |
34 | 34 | <?php |
35 | - endforeach; |
|
36 | - } |
|
35 | + endforeach; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @inheritdoc |
|
40 | - */ |
|
41 | - protected function enqueue_resources() { |
|
42 | - // Enqueue select2 library js and css. |
|
43 | - // Underscore is needed for Select2's `templateResult` and `templateSelection` templates. |
|
44 | - wp_enqueue_script( |
|
45 | - 'wordlift-select2', |
|
46 | - plugin_dir_url( __DIR__ ) . 'js/select2/js/select2' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.js', |
|
47 | - array( |
|
48 | - 'jquery', |
|
49 | - 'underscore', |
|
50 | - ), |
|
51 | - '4.0.3', |
|
52 | - false |
|
53 | - ); |
|
54 | - wp_enqueue_style( 'wordlift-select2', plugin_dir_url( __DIR__ ) . 'js/select2/css/select2' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), '4.0.3' ); |
|
55 | - } |
|
38 | + /** |
|
39 | + * @inheritdoc |
|
40 | + */ |
|
41 | + protected function enqueue_resources() { |
|
42 | + // Enqueue select2 library js and css. |
|
43 | + // Underscore is needed for Select2's `templateResult` and `templateSelection` templates. |
|
44 | + wp_enqueue_script( |
|
45 | + 'wordlift-select2', |
|
46 | + plugin_dir_url( __DIR__ ) . 'js/select2/js/select2' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.js', |
|
47 | + array( |
|
48 | + 'jquery', |
|
49 | + 'underscore', |
|
50 | + ), |
|
51 | + '4.0.3', |
|
52 | + false |
|
53 | + ); |
|
54 | + wp_enqueue_style( 'wordlift-select2', plugin_dir_url( __DIR__ ) . 'js/select2/css/select2' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), '4.0.3' ); |
|
55 | + } |
|
56 | 56 | |
57 | 57 | } |
@@ -21,15 +21,15 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * @inheritdoc |
23 | 23 | */ |
24 | - public function render_options( $params ) { |
|
24 | + public function render_options($params) { |
|
25 | 25 | // Loop through all params and add the options. |
26 | - foreach ( $params['options'] as $value => $label ) : |
|
26 | + foreach ($params['options'] as $value => $label) : |
|
27 | 27 | ?> |
28 | 28 | <option |
29 | - value="<?php echo esc_attr( $value ); ?>" |
|
30 | - <?php selected( $params['value'], $value ); ?> |
|
29 | + value="<?php echo esc_attr($value); ?>" |
|
30 | + <?php selected($params['value'], $value); ?> |
|
31 | 31 | > |
32 | - <?php echo esc_html( $label ); ?> |
|
32 | + <?php echo esc_html($label); ?> |
|
33 | 33 | </option> |
34 | 34 | <?php |
35 | 35 | endforeach; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | // Underscore is needed for Select2's `templateResult` and `templateSelection` templates. |
44 | 44 | wp_enqueue_script( |
45 | 45 | 'wordlift-select2', |
46 | - plugin_dir_url( __DIR__ ) . 'js/select2/js/select2' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.js', |
|
46 | + plugin_dir_url(__DIR__).'js/select2/js/select2'.( ! defined('SCRIPT_DEBUG') || ! SCRIPT_DEBUG ? '.min' : '').'.js', |
|
47 | 47 | array( |
48 | 48 | 'jquery', |
49 | 49 | 'underscore', |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | '4.0.3', |
52 | 52 | false |
53 | 53 | ); |
54 | - wp_enqueue_style( 'wordlift-select2', plugin_dir_url( __DIR__ ) . 'js/select2/css/select2' . ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ? '.min' : '' ) . '.css', array(), '4.0.3' ); |
|
54 | + wp_enqueue_style('wordlift-select2', plugin_dir_url(__DIR__).'js/select2/css/select2'.( ! defined('SCRIPT_DEBUG') || ! SCRIPT_DEBUG ? '.min' : '').'.css', array(), '4.0.3'); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | } |
@@ -18,11 +18,11 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class Wordlift_Admin_Language_Select_Element extends Wordlift_Admin_Select_Element { |
20 | 20 | |
21 | - /** |
|
22 | - * @inheritdoc |
|
23 | - */ |
|
24 | - public function render_options( $params ) { |
|
25 | - /* |
|
21 | + /** |
|
22 | + * @inheritdoc |
|
23 | + */ |
|
24 | + public function render_options( $params ) { |
|
25 | + /* |
|
26 | 26 | * Print all the supported language, preselecting the one configured |
27 | 27 | * in WP (or English if not supported). We now use the `Wordlift_Languages` |
28 | 28 | * class which provides the list of languages supported by WordLift. |
@@ -30,14 +30,14 @@ discard block |
||
30 | 30 | * See https://github.com/insideout10/wordlift-plugin/issues/349 |
31 | 31 | */ |
32 | 32 | |
33 | - // Get WordLift's supported languages. |
|
34 | - $languages = Wordlift_Languages::get_languages(); |
|
33 | + // Get WordLift's supported languages. |
|
34 | + $languages = Wordlift_Languages::get_languages(); |
|
35 | 35 | |
36 | - // If we support WP's configured language, then use that, otherwise use English by default. |
|
37 | - $language = isset( $languages[ $params['value'] ] ) ? $params['value'] : 'en'; |
|
36 | + // If we support WP's configured language, then use that, otherwise use English by default. |
|
37 | + $language = isset( $languages[ $params['value'] ] ) ? $params['value'] : 'en'; |
|
38 | 38 | |
39 | - foreach ( $languages as $code => $label ) : |
|
40 | - ?> |
|
39 | + foreach ( $languages as $code => $label ) : |
|
40 | + ?> |
|
41 | 41 | <option |
42 | 42 | value="<?php echo esc_attr( $code ); ?>" |
43 | 43 | <?php echo selected( $code, $language, false ); ?> |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | <?php echo esc_html( $label ); ?> |
46 | 46 | </option> |
47 | 47 | <?php |
48 | - endforeach; |
|
49 | - } |
|
48 | + endforeach; |
|
49 | + } |
|
50 | 50 | |
51 | 51 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * @inheritdoc |
23 | 23 | */ |
24 | - public function render_options( $params ) { |
|
24 | + public function render_options($params) { |
|
25 | 25 | /* |
26 | 26 | * Print all the supported language, preselecting the one configured |
27 | 27 | * in WP (or English if not supported). We now use the `Wordlift_Languages` |
@@ -34,15 +34,15 @@ discard block |
||
34 | 34 | $languages = Wordlift_Languages::get_languages(); |
35 | 35 | |
36 | 36 | // If we support WP's configured language, then use that, otherwise use English by default. |
37 | - $language = isset( $languages[ $params['value'] ] ) ? $params['value'] : 'en'; |
|
37 | + $language = isset($languages[$params['value']]) ? $params['value'] : 'en'; |
|
38 | 38 | |
39 | - foreach ( $languages as $code => $label ) : |
|
39 | + foreach ($languages as $code => $label) : |
|
40 | 40 | ?> |
41 | 41 | <option |
42 | - value="<?php echo esc_attr( $code ); ?>" |
|
43 | - <?php echo selected( $code, $language, false ); ?> |
|
42 | + value="<?php echo esc_attr($code); ?>" |
|
43 | + <?php echo selected($code, $language, false); ?> |
|
44 | 44 | > |
45 | - <?php echo esc_html( $label ); ?> |
|
45 | + <?php echo esc_html($label); ?> |
|
46 | 46 | </option> |
47 | 47 | <?php |
48 | 48 | endforeach; |
@@ -19,120 +19,120 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class Wordlift_Admin_Publisher_Element extends Wordlift_Admin_Author_Element { |
21 | 21 | |
22 | - /** |
|
23 | - * The {@link Wordlift_Publisher_Service} instance. |
|
24 | - * |
|
25 | - * @since 3.11.0 |
|
26 | - * @access private |
|
27 | - * @var \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
|
28 | - */ |
|
29 | - private $publisher_service; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var Wordlift_Admin_Tabs_Element |
|
33 | - */ |
|
34 | - private $tabs_element; |
|
35 | - |
|
36 | - /** |
|
37 | - * Create a {@link Wordlift_Admin_Publisher_Element} instance. |
|
38 | - * |
|
39 | - * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
|
40 | - * @param \Wordlift_Admin_Tabs_Element $tabs_element The {@link Wordlift_Admin_Tabs_Element} instance. |
|
41 | - * @param \Wordlift_Admin_Select2_Element $select_element The {@link Wordlift_Admin_Select_Element} instance. |
|
42 | - * |
|
43 | - * @since 3.11.0 |
|
44 | - */ |
|
45 | - public function __construct( $publisher_service, $tabs_element, $select_element ) { |
|
46 | - parent::__construct( $publisher_service, $select_element ); |
|
47 | - |
|
48 | - $this->publisher_service = $publisher_service; |
|
49 | - |
|
50 | - // Child elements. |
|
51 | - $this->tabs_element = $tabs_element; |
|
52 | - |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @inheritdoc |
|
57 | - */ |
|
58 | - public function render( $args ) { |
|
59 | - |
|
60 | - // Parse the arguments and merge with default values. |
|
61 | - $params = wp_parse_args( |
|
62 | - $args, |
|
63 | - array( |
|
64 | - 'id' => uniqid( 'wl-input-' ), |
|
65 | - 'name' => uniqid( 'wl-input-' ), |
|
66 | - ) |
|
67 | - ); |
|
68 | - |
|
69 | - // Get the number of potential candidates as publishers. |
|
70 | - $count = $this->publisher_service->count(); |
|
71 | - |
|
72 | - $this->tabs_element->render( |
|
73 | - array( |
|
74 | - 'tabs' => array( |
|
75 | - array( |
|
76 | - 'label' => __( 'Select an Existing Publisher', 'wordlift' ), |
|
77 | - 'callback' => array( $this, 'select' ), |
|
78 | - 'args' => $params, |
|
79 | - ), |
|
80 | - array( |
|
81 | - 'label' => __( 'Create a New Publisher', 'wordlift' ), |
|
82 | - 'callback' => array( $this, 'create' ), |
|
83 | - 'args' => $params, |
|
84 | - ), |
|
85 | - ), |
|
86 | - // Set the default tab according to the number of potential publishers |
|
87 | - // configured in WP: 0 = select, 1 = create. |
|
88 | - 'active' => 0 === $count ? 1 : 0, |
|
89 | - ) |
|
90 | - ); |
|
91 | - |
|
92 | - // Finally return the element instance. |
|
93 | - return $this; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Render the publisher's select. |
|
98 | - * |
|
99 | - * @param array $params An array of parameters. |
|
100 | - * |
|
101 | - * @since 3.11.0 |
|
102 | - */ |
|
103 | - public function select( $params ) { |
|
104 | - |
|
105 | - // Get the configured publisher id. In case a publisher id is already configured |
|
106 | - // this must be pre-loaded in the options. |
|
107 | - $publisher_id = Wordlift_Configuration_Service::get_instance()->get_publisher_id(); |
|
108 | - |
|
109 | - // Get the publisher data. |
|
110 | - $data = $this->publisher_service->query(); |
|
111 | - array_unshift( |
|
112 | - $data, |
|
113 | - array( |
|
114 | - 'id' => '', |
|
115 | - 'text' => _x( '(none)', 'Publisher Select in Settings Screen.', 'wordlift' ), |
|
116 | - 'type' => '', |
|
117 | - 'thumbnail_url' => false, |
|
118 | - ) |
|
119 | - ); |
|
120 | - |
|
121 | - // Call the select internal render. |
|
122 | - $this->do_render( $params, $publisher_id, $data ); |
|
123 | - |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Render the 'create publisher' form. |
|
128 | - * |
|
129 | - * @param array $params An array of parameters. |
|
130 | - * |
|
131 | - * @since 3.11.0 |
|
132 | - */ |
|
22 | + /** |
|
23 | + * The {@link Wordlift_Publisher_Service} instance. |
|
24 | + * |
|
25 | + * @since 3.11.0 |
|
26 | + * @access private |
|
27 | + * @var \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
|
28 | + */ |
|
29 | + private $publisher_service; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var Wordlift_Admin_Tabs_Element |
|
33 | + */ |
|
34 | + private $tabs_element; |
|
35 | + |
|
36 | + /** |
|
37 | + * Create a {@link Wordlift_Admin_Publisher_Element} instance. |
|
38 | + * |
|
39 | + * @param \Wordlift_Publisher_Service $publisher_service The {@link Wordlift_Publisher_Service} instance. |
|
40 | + * @param \Wordlift_Admin_Tabs_Element $tabs_element The {@link Wordlift_Admin_Tabs_Element} instance. |
|
41 | + * @param \Wordlift_Admin_Select2_Element $select_element The {@link Wordlift_Admin_Select_Element} instance. |
|
42 | + * |
|
43 | + * @since 3.11.0 |
|
44 | + */ |
|
45 | + public function __construct( $publisher_service, $tabs_element, $select_element ) { |
|
46 | + parent::__construct( $publisher_service, $select_element ); |
|
47 | + |
|
48 | + $this->publisher_service = $publisher_service; |
|
49 | + |
|
50 | + // Child elements. |
|
51 | + $this->tabs_element = $tabs_element; |
|
52 | + |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @inheritdoc |
|
57 | + */ |
|
58 | + public function render( $args ) { |
|
59 | + |
|
60 | + // Parse the arguments and merge with default values. |
|
61 | + $params = wp_parse_args( |
|
62 | + $args, |
|
63 | + array( |
|
64 | + 'id' => uniqid( 'wl-input-' ), |
|
65 | + 'name' => uniqid( 'wl-input-' ), |
|
66 | + ) |
|
67 | + ); |
|
68 | + |
|
69 | + // Get the number of potential candidates as publishers. |
|
70 | + $count = $this->publisher_service->count(); |
|
71 | + |
|
72 | + $this->tabs_element->render( |
|
73 | + array( |
|
74 | + 'tabs' => array( |
|
75 | + array( |
|
76 | + 'label' => __( 'Select an Existing Publisher', 'wordlift' ), |
|
77 | + 'callback' => array( $this, 'select' ), |
|
78 | + 'args' => $params, |
|
79 | + ), |
|
80 | + array( |
|
81 | + 'label' => __( 'Create a New Publisher', 'wordlift' ), |
|
82 | + 'callback' => array( $this, 'create' ), |
|
83 | + 'args' => $params, |
|
84 | + ), |
|
85 | + ), |
|
86 | + // Set the default tab according to the number of potential publishers |
|
87 | + // configured in WP: 0 = select, 1 = create. |
|
88 | + 'active' => 0 === $count ? 1 : 0, |
|
89 | + ) |
|
90 | + ); |
|
91 | + |
|
92 | + // Finally return the element instance. |
|
93 | + return $this; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Render the publisher's select. |
|
98 | + * |
|
99 | + * @param array $params An array of parameters. |
|
100 | + * |
|
101 | + * @since 3.11.0 |
|
102 | + */ |
|
103 | + public function select( $params ) { |
|
104 | + |
|
105 | + // Get the configured publisher id. In case a publisher id is already configured |
|
106 | + // this must be pre-loaded in the options. |
|
107 | + $publisher_id = Wordlift_Configuration_Service::get_instance()->get_publisher_id(); |
|
108 | + |
|
109 | + // Get the publisher data. |
|
110 | + $data = $this->publisher_service->query(); |
|
111 | + array_unshift( |
|
112 | + $data, |
|
113 | + array( |
|
114 | + 'id' => '', |
|
115 | + 'text' => _x( '(none)', 'Publisher Select in Settings Screen.', 'wordlift' ), |
|
116 | + 'type' => '', |
|
117 | + 'thumbnail_url' => false, |
|
118 | + ) |
|
119 | + ); |
|
120 | + |
|
121 | + // Call the select internal render. |
|
122 | + $this->do_render( $params, $publisher_id, $data ); |
|
123 | + |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Render the 'create publisher' form. |
|
128 | + * |
|
129 | + * @param array $params An array of parameters. |
|
130 | + * |
|
131 | + * @since 3.11.0 |
|
132 | + */ |
|
133 | 133 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
134 | - public function create( $params ) { |
|
135 | - ?> |
|
134 | + public function create( $params ) { |
|
135 | + ?> |
|
136 | 136 | <p> |
137 | 137 | <strong><?php esc_html_e( 'Are you publishing as an individual or as a company?', 'wordlift' ); ?></strong> |
138 | 138 | </p> |
@@ -197,6 +197,6 @@ discard block |
||
197 | 197 | </p> |
198 | 198 | </div> |
199 | 199 | <?php |
200 | - } |
|
200 | + } |
|
201 | 201 | |
202 | 202 | } |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @since 3.11.0 |
44 | 44 | */ |
45 | - public function __construct( $publisher_service, $tabs_element, $select_element ) { |
|
46 | - parent::__construct( $publisher_service, $select_element ); |
|
45 | + public function __construct($publisher_service, $tabs_element, $select_element) { |
|
46 | + parent::__construct($publisher_service, $select_element); |
|
47 | 47 | |
48 | 48 | $this->publisher_service = $publisher_service; |
49 | 49 | |
@@ -55,14 +55,14 @@ discard block |
||
55 | 55 | /** |
56 | 56 | * @inheritdoc |
57 | 57 | */ |
58 | - public function render( $args ) { |
|
58 | + public function render($args) { |
|
59 | 59 | |
60 | 60 | // Parse the arguments and merge with default values. |
61 | 61 | $params = wp_parse_args( |
62 | 62 | $args, |
63 | 63 | array( |
64 | - 'id' => uniqid( 'wl-input-' ), |
|
65 | - 'name' => uniqid( 'wl-input-' ), |
|
64 | + 'id' => uniqid('wl-input-'), |
|
65 | + 'name' => uniqid('wl-input-'), |
|
66 | 66 | ) |
67 | 67 | ); |
68 | 68 | |
@@ -73,13 +73,13 @@ discard block |
||
73 | 73 | array( |
74 | 74 | 'tabs' => array( |
75 | 75 | array( |
76 | - 'label' => __( 'Select an Existing Publisher', 'wordlift' ), |
|
77 | - 'callback' => array( $this, 'select' ), |
|
76 | + 'label' => __('Select an Existing Publisher', 'wordlift'), |
|
77 | + 'callback' => array($this, 'select'), |
|
78 | 78 | 'args' => $params, |
79 | 79 | ), |
80 | 80 | array( |
81 | - 'label' => __( 'Create a New Publisher', 'wordlift' ), |
|
82 | - 'callback' => array( $this, 'create' ), |
|
81 | + 'label' => __('Create a New Publisher', 'wordlift'), |
|
82 | + 'callback' => array($this, 'create'), |
|
83 | 83 | 'args' => $params, |
84 | 84 | ), |
85 | 85 | ), |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @since 3.11.0 |
102 | 102 | */ |
103 | - public function select( $params ) { |
|
103 | + public function select($params) { |
|
104 | 104 | |
105 | 105 | // Get the configured publisher id. In case a publisher id is already configured |
106 | 106 | // this must be pre-loaded in the options. |
@@ -112,14 +112,14 @@ discard block |
||
112 | 112 | $data, |
113 | 113 | array( |
114 | 114 | 'id' => '', |
115 | - 'text' => _x( '(none)', 'Publisher Select in Settings Screen.', 'wordlift' ), |
|
115 | + 'text' => _x('(none)', 'Publisher Select in Settings Screen.', 'wordlift'), |
|
116 | 116 | 'type' => '', |
117 | 117 | 'thumbnail_url' => false, |
118 | 118 | ) |
119 | 119 | ); |
120 | 120 | |
121 | 121 | // Call the select internal render. |
122 | - $this->do_render( $params, $publisher_id, $data ); |
|
122 | + $this->do_render($params, $publisher_id, $data); |
|
123 | 123 | |
124 | 124 | } |
125 | 125 | |
@@ -131,10 +131,10 @@ discard block |
||
131 | 131 | * @since 3.11.0 |
132 | 132 | */ |
133 | 133 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
134 | - public function create( $params ) { |
|
134 | + public function create($params) { |
|
135 | 135 | ?> |
136 | 136 | <p> |
137 | - <strong><?php esc_html_e( 'Are you publishing as an individual or as a company?', 'wordlift' ); ?></strong> |
|
137 | + <strong><?php esc_html_e('Are you publishing as an individual or as a company?', 'wordlift'); ?></strong> |
|
138 | 138 | </p> |
139 | 139 | |
140 | 140 | <p id="wl-publisher-type"> |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | > |
149 | 149 | |
150 | 150 | <label for="wl-publisher-person"> |
151 | - <?php esc_html_e( 'Person', 'wordlift' ); ?> |
|
151 | + <?php esc_html_e('Person', 'wordlift'); ?> |
|
152 | 152 | </label> |
153 | 153 | </span> |
154 | 154 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | > |
162 | 162 | |
163 | 163 | <label for="wl-publisher-company"> |
164 | - <?php esc_html_e( 'Company', 'wordlift' ); ?> |
|
164 | + <?php esc_html_e('Company', 'wordlift'); ?> |
|
165 | 165 | </label> |
166 | 166 | </span> |
167 | 167 | </p> |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | <input |
171 | 171 | type="text" |
172 | 172 | name="wl_publisher[name]" |
173 | - placeholder="<?php echo esc_attr__( "What's your name?", 'wordlift' ); ?>" |
|
173 | + placeholder="<?php echo esc_attr__("What's your name?", 'wordlift'); ?>" |
|
174 | 174 | > |
175 | 175 | </p> |
176 | 176 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | /> |
183 | 183 | |
184 | 184 | <p> |
185 | - <b><?php esc_html_e( "Choose the publisher's Logo", 'wordlift' ); ?></b> |
|
185 | + <b><?php esc_html_e("Choose the publisher's Logo", 'wordlift'); ?></b> |
|
186 | 186 | </p> |
187 | 187 | |
188 | 188 | <p> |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | type="button" |
193 | 193 | class="button" |
194 | 194 | id="wl-publisher-media-uploader"> |
195 | - <?php esc_html_e( 'Select an existing image or upload a new one', 'wordlift' ); ?> |
|
195 | + <?php esc_html_e('Select an existing image or upload a new one', 'wordlift'); ?> |
|
196 | 196 | </button> |
197 | 197 | </p> |
198 | 198 | </div> |
@@ -19,55 +19,55 @@ |
||
19 | 19 | */ |
20 | 20 | class Wordlift_Admin_Settings_Analytics_Page_Action_Link { |
21 | 21 | |
22 | - /** |
|
23 | - * The {@link Wordlift_Admin_Settings_Analytics_Page} instance. |
|
24 | - * |
|
25 | - * @since 3.11.0 |
|
26 | - * @access private |
|
27 | - * @var \Wordlift_Admin_Settings_Analytics_Page $settings_page The {@link Wordlift_Admin_Settings_Analytics_Page} instance. |
|
28 | - */ |
|
29 | - private $settings_page; |
|
22 | + /** |
|
23 | + * The {@link Wordlift_Admin_Settings_Analytics_Page} instance. |
|
24 | + * |
|
25 | + * @since 3.11.0 |
|
26 | + * @access private |
|
27 | + * @var \Wordlift_Admin_Settings_Analytics_Page $settings_page The {@link Wordlift_Admin_Settings_Analytics_Page} instance. |
|
28 | + */ |
|
29 | + private $settings_page; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Create a {@link Wordlift_Admin_Settings_Analytics_Page_Action_Link} instance. |
|
33 | - * |
|
34 | - * @since 3.11.0 |
|
35 | - * |
|
36 | - * @param \Wordlift_Admin_Settings_Analytics_Page $settings_page The {@link Wordlift_Admin_Settings_Analytics_Page} instance. |
|
37 | - */ |
|
38 | - public function __construct( $settings_page ) { |
|
31 | + /** |
|
32 | + * Create a {@link Wordlift_Admin_Settings_Analytics_Page_Action_Link} instance. |
|
33 | + * |
|
34 | + * @since 3.11.0 |
|
35 | + * |
|
36 | + * @param \Wordlift_Admin_Settings_Analytics_Page $settings_page The {@link Wordlift_Admin_Settings_Analytics_Page} instance. |
|
37 | + */ |
|
38 | + public function __construct( $settings_page ) { |
|
39 | 39 | |
40 | - $this->settings_page = $settings_page; |
|
40 | + $this->settings_page = $settings_page; |
|
41 | 41 | |
42 | - } |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Create a link to the WordLift settings page. |
|
46 | - * |
|
47 | - * @since 3.11.0 |
|
48 | - * |
|
49 | - * @param array $links An array of links. |
|
50 | - * |
|
51 | - * @return array An array of links including those added by the plugin. |
|
52 | - */ |
|
53 | - public function action_links( $links ) { |
|
44 | + /** |
|
45 | + * Create a link to the WordLift settings page. |
|
46 | + * |
|
47 | + * @since 3.11.0 |
|
48 | + * |
|
49 | + * @param array $links An array of links. |
|
50 | + * |
|
51 | + * @return array An array of links including those added by the plugin. |
|
52 | + */ |
|
53 | + public function action_links( $links ) { |
|
54 | 54 | |
55 | - // Get the menu slug from the page, then prepare the path, hence the url. |
|
56 | - $menu_slug = $this->settings_page->get_menu_slug(); |
|
57 | - $path = "admin.php?page=$menu_slug"; |
|
58 | - $url = get_admin_url( null, $path ); |
|
55 | + // Get the menu slug from the page, then prepare the path, hence the url. |
|
56 | + $menu_slug = $this->settings_page->get_menu_slug(); |
|
57 | + $path = "admin.php?page=$menu_slug"; |
|
58 | + $url = get_admin_url( null, $path ); |
|
59 | 59 | |
60 | - // Add our own link to the list of links. |
|
61 | - return array_merge( |
|
62 | - $links, |
|
63 | - array( |
|
64 | - sprintf( |
|
65 | - '<a href="%1$s">%2$s</a>', |
|
66 | - esc_url( $url ), |
|
67 | - esc_html__( 'Analytics Settings', 'wordlift' ) |
|
68 | - ), |
|
69 | - ) |
|
70 | - ); |
|
71 | - } |
|
60 | + // Add our own link to the list of links. |
|
61 | + return array_merge( |
|
62 | + $links, |
|
63 | + array( |
|
64 | + sprintf( |
|
65 | + '<a href="%1$s">%2$s</a>', |
|
66 | + esc_url( $url ), |
|
67 | + esc_html__( 'Analytics Settings', 'wordlift' ) |
|
68 | + ), |
|
69 | + ) |
|
70 | + ); |
|
71 | + } |
|
72 | 72 | |
73 | 73 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * |
36 | 36 | * @param \Wordlift_Admin_Settings_Analytics_Page $settings_page The {@link Wordlift_Admin_Settings_Analytics_Page} instance. |
37 | 37 | */ |
38 | - public function __construct( $settings_page ) { |
|
38 | + public function __construct($settings_page) { |
|
39 | 39 | |
40 | 40 | $this->settings_page = $settings_page; |
41 | 41 | |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return array An array of links including those added by the plugin. |
52 | 52 | */ |
53 | - public function action_links( $links ) { |
|
53 | + public function action_links($links) { |
|
54 | 54 | |
55 | 55 | // Get the menu slug from the page, then prepare the path, hence the url. |
56 | 56 | $menu_slug = $this->settings_page->get_menu_slug(); |
57 | 57 | $path = "admin.php?page=$menu_slug"; |
58 | - $url = get_admin_url( null, $path ); |
|
58 | + $url = get_admin_url(null, $path); |
|
59 | 59 | |
60 | 60 | // Add our own link to the list of links. |
61 | 61 | return array_merge( |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | array( |
64 | 64 | sprintf( |
65 | 65 | '<a href="%1$s">%2$s</a>', |
66 | - esc_url( $url ), |
|
67 | - esc_html__( 'Analytics Settings', 'wordlift' ) |
|
66 | + esc_url($url), |
|
67 | + esc_html__('Analytics Settings', 'wordlift') |
|
68 | 68 | ), |
69 | 69 | ) |
70 | 70 | ); |
@@ -25,24 +25,24 @@ discard block |
||
25 | 25 | */ |
26 | 26 | function wl_transition_post_status( $new_status, $old_status, $post ) { |
27 | 27 | |
28 | - // transition from *published* to any other status: delete the post. |
|
29 | - if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
30 | - // Delete the post from the triple store. |
|
31 | - rl_delete_post( $post ); |
|
32 | - |
|
33 | - // Remove all relation instances for the current post from `wl_relation_instances`. |
|
34 | - wl_core_delete_relation_instances( $post->ID ); |
|
35 | - } |
|
36 | - |
|
37 | - // when a post is published, then all the referenced entities must be published. |
|
38 | - if ( 'publish' !== $old_status && 'publish' === $new_status |
|
39 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
40 | - && apply_filters( 'wl_feature__enable__entity-auto-publish', true ) ) { |
|
41 | - |
|
42 | - foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
43 | - wl_update_post_status( $entity_id, 'publish' ); |
|
44 | - } |
|
45 | - } |
|
28 | + // transition from *published* to any other status: delete the post. |
|
29 | + if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
30 | + // Delete the post from the triple store. |
|
31 | + rl_delete_post( $post ); |
|
32 | + |
|
33 | + // Remove all relation instances for the current post from `wl_relation_instances`. |
|
34 | + wl_core_delete_relation_instances( $post->ID ); |
|
35 | + } |
|
36 | + |
|
37 | + // when a post is published, then all the referenced entities must be published. |
|
38 | + if ( 'publish' !== $old_status && 'publish' === $new_status |
|
39 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
40 | + && apply_filters( 'wl_feature__enable__entity-auto-publish', true ) ) { |
|
41 | + |
|
42 | + foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
43 | + wl_update_post_status( $entity_id, 'publish' ); |
|
44 | + } |
|
45 | + } |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | // hook save events. |
@@ -55,10 +55,10 @@ discard block |
||
55 | 55 | */ |
56 | 56 | function rl_delete_post( $post ) { |
57 | 57 | |
58 | - $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
58 | + $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
59 | 59 | |
60 | - // Remove the post. |
|
61 | - do_action( 'wl_legacy_linked_data__remove', $post_id ); |
|
60 | + // Remove the post. |
|
61 | + do_action( 'wl_legacy_linked_data__remove', $post_id ); |
|
62 | 62 | |
63 | 63 | } |
64 | 64 | |
@@ -70,32 +70,32 @@ discard block |
||
70 | 70 | */ |
71 | 71 | function wl_update_post_status( $post_id, $status ) { |
72 | 72 | |
73 | - global $wpdb; |
|
73 | + global $wpdb; |
|
74 | 74 | |
75 | - $post = get_post( $post_id ); |
|
76 | - if ( ! $post ) { |
|
77 | - return; |
|
78 | - } |
|
75 | + $post = get_post( $post_id ); |
|
76 | + if ( ! $post ) { |
|
77 | + return; |
|
78 | + } |
|
79 | 79 | |
80 | - if ( $status === $post->post_status ) { |
|
81 | - return; |
|
82 | - } |
|
80 | + if ( $status === $post->post_status ) { |
|
81 | + return; |
|
82 | + } |
|
83 | 83 | |
84 | - $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
84 | + $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
85 | 85 | |
86 | - clean_post_cache( $post->ID ); |
|
86 | + clean_post_cache( $post->ID ); |
|
87 | 87 | |
88 | - $old_status = $post->post_status; |
|
89 | - $post->post_status = $status; |
|
88 | + $old_status = $post->post_status; |
|
89 | + $post->post_status = $status; |
|
90 | 90 | |
91 | - wp_transition_post_status( $status, $old_status, $post ); |
|
91 | + wp_transition_post_status( $status, $old_status, $post ); |
|
92 | 92 | |
93 | - /** This action is documented in wp-includes/post.php */ |
|
94 | - do_action( 'edit_post', $post->ID, $post ); |
|
95 | - /** This action is documented in wp-includes/post.php */ |
|
96 | - do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
97 | - /** This action is documented in wp-includes/post.php */ |
|
98 | - do_action( 'wl_linked_data_save_post', $post->ID ); |
|
99 | - /** This action is documented in wp-includes/post.php */ |
|
100 | - do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
93 | + /** This action is documented in wp-includes/post.php */ |
|
94 | + do_action( 'edit_post', $post->ID, $post ); |
|
95 | + /** This action is documented in wp-includes/post.php */ |
|
96 | + do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
97 | + /** This action is documented in wp-includes/post.php */ |
|
98 | + do_action( 'wl_linked_data_save_post', $post->ID ); |
|
99 | + /** This action is documented in wp-includes/post.php */ |
|
100 | + do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
101 | 101 | } |
@@ -23,42 +23,42 @@ discard block |
||
23 | 23 | * @param string $old_status The old post status |
24 | 24 | * @param array $post An array with the post data |
25 | 25 | */ |
26 | -function wl_transition_post_status( $new_status, $old_status, $post ) { |
|
26 | +function wl_transition_post_status($new_status, $old_status, $post) { |
|
27 | 27 | |
28 | 28 | // transition from *published* to any other status: delete the post. |
29 | - if ( 'publish' === $old_status && 'publish' !== $new_status ) { |
|
29 | + if ('publish' === $old_status && 'publish' !== $new_status) { |
|
30 | 30 | // Delete the post from the triple store. |
31 | - rl_delete_post( $post ); |
|
31 | + rl_delete_post($post); |
|
32 | 32 | |
33 | 33 | // Remove all relation instances for the current post from `wl_relation_instances`. |
34 | - wl_core_delete_relation_instances( $post->ID ); |
|
34 | + wl_core_delete_relation_instances($post->ID); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | // when a post is published, then all the referenced entities must be published. |
38 | - if ( 'publish' !== $old_status && 'publish' === $new_status |
|
38 | + if ('publish' !== $old_status && 'publish' === $new_status |
|
39 | 39 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
40 | - && apply_filters( 'wl_feature__enable__entity-auto-publish', true ) ) { |
|
40 | + && apply_filters('wl_feature__enable__entity-auto-publish', true)) { |
|
41 | 41 | |
42 | - foreach ( wl_core_get_related_entity_ids( $post->ID ) as $entity_id ) { |
|
43 | - wl_update_post_status( $entity_id, 'publish' ); |
|
42 | + foreach (wl_core_get_related_entity_ids($post->ID) as $entity_id) { |
|
43 | + wl_update_post_status($entity_id, 'publish'); |
|
44 | 44 | } |
45 | 45 | } |
46 | 46 | } |
47 | 47 | |
48 | 48 | // hook save events. |
49 | -add_action( 'transition_post_status', 'wl_transition_post_status', 10, 3 ); |
|
49 | +add_action('transition_post_status', 'wl_transition_post_status', 10, 3); |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Delete the specified post from the triple store. |
53 | 53 | * |
54 | 54 | * @param array|int $post An array of post data |
55 | 55 | */ |
56 | -function rl_delete_post( $post ) { |
|
56 | +function rl_delete_post($post) { |
|
57 | 57 | |
58 | - $post_id = ( is_numeric( $post ) ? $post : $post->ID ); |
|
58 | + $post_id = (is_numeric($post) ? $post : $post->ID); |
|
59 | 59 | |
60 | 60 | // Remove the post. |
61 | - do_action( 'wl_legacy_linked_data__remove', $post_id ); |
|
61 | + do_action('wl_legacy_linked_data__remove', $post_id); |
|
62 | 62 | |
63 | 63 | } |
64 | 64 | |
@@ -68,34 +68,34 @@ discard block |
||
68 | 68 | * @param int $post_id The post ID |
69 | 69 | * @param string $status The new status |
70 | 70 | */ |
71 | -function wl_update_post_status( $post_id, $status ) { |
|
71 | +function wl_update_post_status($post_id, $status) { |
|
72 | 72 | |
73 | 73 | global $wpdb; |
74 | 74 | |
75 | - $post = get_post( $post_id ); |
|
76 | - if ( ! $post ) { |
|
75 | + $post = get_post($post_id); |
|
76 | + if ( ! $post) { |
|
77 | 77 | return; |
78 | 78 | } |
79 | 79 | |
80 | - if ( $status === $post->post_status ) { |
|
80 | + if ($status === $post->post_status) { |
|
81 | 81 | return; |
82 | 82 | } |
83 | 83 | |
84 | - $wpdb->update( $wpdb->posts, array( 'post_status' => $status ), array( 'ID' => $post->ID ) ); |
|
84 | + $wpdb->update($wpdb->posts, array('post_status' => $status), array('ID' => $post->ID)); |
|
85 | 85 | |
86 | - clean_post_cache( $post->ID ); |
|
86 | + clean_post_cache($post->ID); |
|
87 | 87 | |
88 | 88 | $old_status = $post->post_status; |
89 | 89 | $post->post_status = $status; |
90 | 90 | |
91 | - wp_transition_post_status( $status, $old_status, $post ); |
|
91 | + wp_transition_post_status($status, $old_status, $post); |
|
92 | 92 | |
93 | 93 | /** This action is documented in wp-includes/post.php */ |
94 | - do_action( 'edit_post', $post->ID, $post ); |
|
94 | + do_action('edit_post', $post->ID, $post); |
|
95 | 95 | /** This action is documented in wp-includes/post.php */ |
96 | - do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); |
|
96 | + do_action("save_post_{$post->post_type}", $post->ID, $post, true); |
|
97 | 97 | /** This action is documented in wp-includes/post.php */ |
98 | - do_action( 'wl_linked_data_save_post', $post->ID ); |
|
98 | + do_action('wl_linked_data_save_post', $post->ID); |
|
99 | 99 | /** This action is documented in wp-includes/post.php */ |
100 | - do_action( 'wp_insert_post', $post->ID, $post, true ); |
|
100 | + do_action('wp_insert_post', $post->ID, $post, true); |
|
101 | 101 | } |
@@ -15,25 +15,25 @@ discard block |
||
15 | 15 | */ |
16 | 16 | function wl_admin_menu() { |
17 | 17 | |
18 | - $menu_slug = 'wl_admin_menu'; |
|
19 | - $capability = 'manage_options'; |
|
18 | + $menu_slug = 'wl_admin_menu'; |
|
19 | + $capability = 'manage_options'; |
|
20 | 20 | |
21 | - // see http://codex.wordpress.org/Function_Reference/add_menu_page |
|
22 | - add_menu_page( |
|
23 | - __( 'WordLift', 'wordlift' ), // page title |
|
24 | - __( 'WordLift', 'wordlift' ), // menu title |
|
25 | - $capability, // capabilities |
|
26 | - $menu_slug, // menu slug |
|
27 | - // 'wl_admin_menu_callback', // TODO: function callback to draw the coming dashboard |
|
28 | - 'wl_configuration_admin_menu_callback', |
|
29 | - WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-logo-icon.svg' |
|
30 | - ); // icon URL 20x20 px |
|
21 | + // see http://codex.wordpress.org/Function_Reference/add_menu_page |
|
22 | + add_menu_page( |
|
23 | + __( 'WordLift', 'wordlift' ), // page title |
|
24 | + __( 'WordLift', 'wordlift' ), // menu title |
|
25 | + $capability, // capabilities |
|
26 | + $menu_slug, // menu slug |
|
27 | + // 'wl_admin_menu_callback', // TODO: function callback to draw the coming dashboard |
|
28 | + 'wl_configuration_admin_menu_callback', |
|
29 | + WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-logo-icon.svg' |
|
30 | + ); // icon URL 20x20 px |
|
31 | 31 | |
32 | - // Call hooked functions. |
|
33 | - do_action( 'wl_admin_menu', $menu_slug, $capability ); |
|
32 | + // Call hooked functions. |
|
33 | + do_action( 'wl_admin_menu', $menu_slug, $capability ); |
|
34 | 34 | |
35 | - // Remove duplicate 'WordLift' subpage created by WordPress. |
|
36 | - remove_submenu_page( $menu_slug, $menu_slug ); |
|
35 | + // Remove duplicate 'WordLift' subpage created by WordPress. |
|
36 | + remove_submenu_page( $menu_slug, $menu_slug ); |
|
37 | 37 | |
38 | 38 | } |
39 | 39 | |
@@ -47,20 +47,20 @@ discard block |
||
47 | 47 | * @since 3.15.0 |
48 | 48 | */ |
49 | 49 | function wl_remove_entity_type_menu() { |
50 | - /* |
|
50 | + /* |
|
51 | 51 | * Remove from the menu links to the entity type admin page when |
52 | 52 | * under non entity hierarchy. |
53 | 53 | */ |
54 | - foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $post_type ) { |
|
55 | - // In the context of admin menues post has no explicit indication of post type in the urls. |
|
56 | - if ( 'post' !== $post_type ) { |
|
57 | - remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=' . Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
58 | - } |
|
54 | + foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $post_type ) { |
|
55 | + // In the context of admin menues post has no explicit indication of post type in the urls. |
|
56 | + if ( 'post' !== $post_type ) { |
|
57 | + remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=' . Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
58 | + } |
|
59 | 59 | |
60 | - if ( Wordlift_Entity_Service::TYPE_NAME !== $post_type ) { |
|
61 | - remove_submenu_page( 'edit.php?post_type=' . $post_type, 'edit-tags.php?taxonomy=' . Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME . '&post_type=' . $post_type ); |
|
62 | - } |
|
63 | - } |
|
60 | + if ( Wordlift_Entity_Service::TYPE_NAME !== $post_type ) { |
|
61 | + remove_submenu_page( 'edit.php?post_type=' . $post_type, 'edit-tags.php?taxonomy=' . Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME . '&post_type=' . $post_type ); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | add_action( 'admin_menu', 'wl_remove_entity_type_menu', 100 ); |
@@ -72,12 +72,12 @@ discard block |
||
72 | 72 | */ |
73 | 73 | function wl_admin_menu_callback() { |
74 | 74 | |
75 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
76 | - wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'default' ) ); |
|
77 | - } |
|
75 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
76 | + wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'default' ) ); |
|
77 | + } |
|
78 | 78 | |
79 | - echo '<div class="wrap">'; |
|
80 | - echo '<p>Here is where the form would go if I actually had options.</p>'; |
|
81 | - echo '</div>'; |
|
79 | + echo '<div class="wrap">'; |
|
80 | + echo '<p>Here is where the form would go if I actually had options.</p>'; |
|
81 | + echo '</div>'; |
|
82 | 82 | |
83 | 83 | } |
@@ -20,24 +20,24 @@ discard block |
||
20 | 20 | |
21 | 21 | // see http://codex.wordpress.org/Function_Reference/add_menu_page |
22 | 22 | add_menu_page( |
23 | - __( 'WordLift', 'wordlift' ), // page title |
|
24 | - __( 'WordLift', 'wordlift' ), // menu title |
|
25 | - $capability, // capabilities |
|
26 | - $menu_slug, // menu slug |
|
23 | + __('WordLift', 'wordlift'), // page title |
|
24 | + __('WordLift', 'wordlift'), // menu title |
|
25 | + $capability, // capabilities |
|
26 | + $menu_slug, // menu slug |
|
27 | 27 | // 'wl_admin_menu_callback', // TODO: function callback to draw the coming dashboard |
28 | 28 | 'wl_configuration_admin_menu_callback', |
29 | - WP_CONTENT_URL . '/plugins/wordlift/images/svg/wl-logo-icon.svg' |
|
30 | - ); // icon URL 20x20 px |
|
29 | + WP_CONTENT_URL.'/plugins/wordlift/images/svg/wl-logo-icon.svg' |
|
30 | + ); // icon URL 20x20 px |
|
31 | 31 | |
32 | 32 | // Call hooked functions. |
33 | - do_action( 'wl_admin_menu', $menu_slug, $capability ); |
|
33 | + do_action('wl_admin_menu', $menu_slug, $capability); |
|
34 | 34 | |
35 | 35 | // Remove duplicate 'WordLift' subpage created by WordPress. |
36 | - remove_submenu_page( $menu_slug, $menu_slug ); |
|
36 | + remove_submenu_page($menu_slug, $menu_slug); |
|
37 | 37 | |
38 | 38 | } |
39 | 39 | |
40 | -add_action( 'admin_menu', 'wl_admin_menu' ); |
|
40 | +add_action('admin_menu', 'wl_admin_menu'); |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * This function is called by the *admin_menu* hook to remove for the admin menu |
@@ -51,19 +51,19 @@ discard block |
||
51 | 51 | * Remove from the menu links to the entity type admin page when |
52 | 52 | * under non entity hierarchy. |
53 | 53 | */ |
54 | - foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $post_type ) { |
|
54 | + foreach (Wordlift_Entity_Service::valid_entity_post_types() as $post_type) { |
|
55 | 55 | // In the context of admin menues post has no explicit indication of post type in the urls. |
56 | - if ( 'post' !== $post_type ) { |
|
57 | - remove_submenu_page( 'edit.php', 'edit-tags.php?taxonomy=' . Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
56 | + if ('post' !== $post_type) { |
|
57 | + remove_submenu_page('edit.php', 'edit-tags.php?taxonomy='.Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME); |
|
58 | 58 | } |
59 | 59 | |
60 | - if ( Wordlift_Entity_Service::TYPE_NAME !== $post_type ) { |
|
61 | - remove_submenu_page( 'edit.php?post_type=' . $post_type, 'edit-tags.php?taxonomy=' . Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME . '&post_type=' . $post_type ); |
|
60 | + if (Wordlift_Entity_Service::TYPE_NAME !== $post_type) { |
|
61 | + remove_submenu_page('edit.php?post_type='.$post_type, 'edit-tags.php?taxonomy='.Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME.'&post_type='.$post_type); |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
66 | -add_action( 'admin_menu', 'wl_remove_entity_type_menu', 100 ); |
|
66 | +add_action('admin_menu', 'wl_remove_entity_type_menu', 100); |
|
67 | 67 | |
68 | 68 | /** |
69 | 69 | * This function is called as a callback by the *wl_admin_menu* to display the actual page. |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | */ |
73 | 73 | function wl_admin_menu_callback() { |
74 | 74 | |
75 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
76 | - wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'default' ) ); |
|
75 | + if ( ! current_user_can('manage_options')) { |
|
76 | + wp_die(esc_html__('You do not have sufficient permissions to access this page.', 'default')); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | echo '<div class="wrap">'; |
@@ -18,50 +18,50 @@ |
||
18 | 18 | */ |
19 | 19 | class Wordlift_Admin_Settings_Page_Action_Link { |
20 | 20 | |
21 | - /** |
|
22 | - * The {@link Wordlift_Admin_Settings_Page} instance. |
|
23 | - * |
|
24 | - * @since 3.11.0 |
|
25 | - * @access private |
|
26 | - * @var Wordlift_Admin_Settings_Page $settings_page The {@link Wordlift_Admin_Settings_Page} instance. |
|
27 | - */ |
|
28 | - private $settings_page; |
|
21 | + /** |
|
22 | + * The {@link Wordlift_Admin_Settings_Page} instance. |
|
23 | + * |
|
24 | + * @since 3.11.0 |
|
25 | + * @access private |
|
26 | + * @var Wordlift_Admin_Settings_Page $settings_page The {@link Wordlift_Admin_Settings_Page} instance. |
|
27 | + */ |
|
28 | + private $settings_page; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Create a {@link Wordlift_Admin_Settings_Page_Action_Link} instance. |
|
32 | - * |
|
33 | - * @param Wordlift_Admin_Settings_Page $settings_page The {@link Wordlift_Admin_Settings_Page} instance. |
|
34 | - * |
|
35 | - * @since 3.11.0 |
|
36 | - */ |
|
37 | - public function __construct( $settings_page ) { |
|
30 | + /** |
|
31 | + * Create a {@link Wordlift_Admin_Settings_Page_Action_Link} instance. |
|
32 | + * |
|
33 | + * @param Wordlift_Admin_Settings_Page $settings_page The {@link Wordlift_Admin_Settings_Page} instance. |
|
34 | + * |
|
35 | + * @since 3.11.0 |
|
36 | + */ |
|
37 | + public function __construct( $settings_page ) { |
|
38 | 38 | |
39 | - $this->settings_page = $settings_page; |
|
39 | + $this->settings_page = $settings_page; |
|
40 | 40 | |
41 | - } |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Create a link to the WordLift settings page. |
|
45 | - * |
|
46 | - * @param array $links An array of links. |
|
47 | - * |
|
48 | - * @return array An array of links including those added by the plugin. |
|
49 | - * @since 3.11.0 |
|
50 | - */ |
|
51 | - public function action_links( $links ) { |
|
43 | + /** |
|
44 | + * Create a link to the WordLift settings page. |
|
45 | + * |
|
46 | + * @param array $links An array of links. |
|
47 | + * |
|
48 | + * @return array An array of links including those added by the plugin. |
|
49 | + * @since 3.11.0 |
|
50 | + */ |
|
51 | + public function action_links( $links ) { |
|
52 | 52 | |
53 | - // Get the menu slug from the page, then prepare the path, hence the url. |
|
54 | - $menu_slug = $this->settings_page->get_menu_slug(); |
|
55 | - $path = "admin.php?page=$menu_slug"; |
|
56 | - $url = get_admin_url( null, $path ); |
|
53 | + // Get the menu slug from the page, then prepare the path, hence the url. |
|
54 | + $menu_slug = $this->settings_page->get_menu_slug(); |
|
55 | + $path = "admin.php?page=$menu_slug"; |
|
56 | + $url = get_admin_url( null, $path ); |
|
57 | 57 | |
58 | - // Add our own link to the list of links. |
|
59 | - return array_merge( |
|
60 | - $links, |
|
61 | - array( |
|
62 | - sprintf( "<a href='$url'>%s</a>", __( 'Settings', 'wordlift' ) ), |
|
63 | - ) |
|
64 | - ); |
|
65 | - } |
|
58 | + // Add our own link to the list of links. |
|
59 | + return array_merge( |
|
60 | + $links, |
|
61 | + array( |
|
62 | + sprintf( "<a href='$url'>%s</a>", __( 'Settings', 'wordlift' ) ), |
|
63 | + ) |
|
64 | + ); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * |
35 | 35 | * @since 3.11.0 |
36 | 36 | */ |
37 | - public function __construct( $settings_page ) { |
|
37 | + public function __construct($settings_page) { |
|
38 | 38 | |
39 | 39 | $this->settings_page = $settings_page; |
40 | 40 | |
@@ -48,18 +48,18 @@ discard block |
||
48 | 48 | * @return array An array of links including those added by the plugin. |
49 | 49 | * @since 3.11.0 |
50 | 50 | */ |
51 | - public function action_links( $links ) { |
|
51 | + public function action_links($links) { |
|
52 | 52 | |
53 | 53 | // Get the menu slug from the page, then prepare the path, hence the url. |
54 | 54 | $menu_slug = $this->settings_page->get_menu_slug(); |
55 | 55 | $path = "admin.php?page=$menu_slug"; |
56 | - $url = get_admin_url( null, $path ); |
|
56 | + $url = get_admin_url(null, $path); |
|
57 | 57 | |
58 | 58 | // Add our own link to the list of links. |
59 | 59 | return array_merge( |
60 | 60 | $links, |
61 | 61 | array( |
62 | - sprintf( "<a href='$url'>%s</a>", __( 'Settings', 'wordlift' ) ), |
|
62 | + sprintf("<a href='$url'>%s</a>", __('Settings', 'wordlift')), |
|
63 | 63 | ) |
64 | 64 | ); |
65 | 65 | } |
@@ -20,163 +20,163 @@ |
||
20 | 20 | */ |
21 | 21 | class Wordlift_Dashboard_Latest_News { |
22 | 22 | |
23 | - /** |
|
24 | - * Add needed hooks for the latest news widget. |
|
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - add_action( |
|
28 | - 'wp_ajax_wordlift_get_latest_news', |
|
29 | - array( |
|
30 | - $this, |
|
31 | - 'ajax_get_latest_news', |
|
32 | - ) |
|
33 | - ); |
|
34 | - add_action( |
|
35 | - 'wp_dashboard_setup', |
|
36 | - array( |
|
37 | - $this, |
|
38 | - 'add_dashboard_latest_news_widget', |
|
39 | - ) |
|
40 | - ); |
|
41 | - |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * Return latest news html. |
|
46 | - */ |
|
47 | - public function render() { |
|
48 | - |
|
49 | - wp_enqueue_script( 'wl-admin-dashboard', plugin_dir_url( __DIR__ ) . 'admin/js/wordlift-admin-dashboard.js', array( 'jquery' ), '3.22.0', true ); |
|
50 | - |
|
51 | - include plugin_dir_path( __FILE__ ) . 'partials/wordlift-admin-news-widget.php'; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Returns latest news data filtered by $start_position. |
|
56 | - * |
|
57 | - * @param int $start_position (news array key start position). |
|
58 | - * |
|
59 | - * @return array Latest posts data. |
|
60 | - */ |
|
61 | - public function get_last_wordlift_articles( $start_position = 0 ) { |
|
62 | - $feed_articles = $this->get_wordlift_articles_data(); |
|
63 | - |
|
64 | - // Filter articles by $start_position |
|
65 | - if ( ! empty( $feed_articles ) ) { |
|
66 | - return array( |
|
67 | - 'posts_data' => array_slice( $feed_articles, $start_position, 3 ), |
|
68 | - 'count' => count( $feed_articles ), |
|
69 | - 'start_position' => $start_position, |
|
70 | - ); |
|
71 | - } |
|
72 | - |
|
73 | - return false; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Returns latest news array data. |
|
78 | - * |
|
79 | - * @uses https://codex.wordpress.org/Function_Reference/fetch_feed |
|
80 | - * @uses https://codex.wordpress.org/Function_Reference/get_locale |
|
81 | - * |
|
82 | - * @param int $articles_number (articles total number). |
|
83 | - * |
|
84 | - * @return array Latest $articles_number feed posts. |
|
85 | - */ |
|
86 | - public function get_wordlift_articles_data( $articles_number = 10 ) { |
|
87 | - // Init cache class |
|
88 | - $cache_sistem_lib = new Wordlift_File_Cache_Service( WL_TEMP_DIR . 'articles/' ); |
|
89 | - $locale = get_locale(); |
|
90 | - $cache_id = 'news_' . gmdate( 'Y_m_d' ) . '_' . $locale; |
|
91 | - $posts_data = array(); |
|
92 | - |
|
93 | - // Get latest articles from cache |
|
94 | - $feed_articles = $cache_sistem_lib->get_cache( $cache_id ); |
|
95 | - if ( false === $feed_articles ) { |
|
96 | - // Check WordPress installation language to define articles rss url |
|
97 | - $feed_uri = ( 'it_IT' === $locale ) ? 'https://wordlift.io/blog/it/feed/' : 'https://wordlift.io/blog/en/feed/'; |
|
98 | - |
|
99 | - // Get rss feed data, the response is cached by default for 12 hours |
|
100 | - $feed = fetch_feed( $feed_uri ); |
|
101 | - if ( ! is_wp_error( $feed ) ) { |
|
102 | - // Build an array of requested $articles_number, starting with element 0 |
|
103 | - $feed_articles = $feed->get_items( 0, $articles_number ); |
|
104 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
105 | - foreach ( $feed_articles as $key => $item ) { |
|
106 | - $data = array( |
|
107 | - // fetch_feed will return the title html decoded. |
|
108 | - 'post_title' => $item->get_title(), |
|
109 | - 'post_date' => $item->get_date( 'j F Y | g:i a' ), |
|
110 | - 'post_url' => self::add_utm_parameter( $item->get_permalink() ), |
|
111 | - // fetch_feed will return the description html (not decoded). |
|
112 | - 'post_description' => $item->get_description(), |
|
113 | - ); |
|
114 | - array_push( $posts_data, $data ); |
|
115 | - } |
|
116 | - // Set articles in cache. |
|
117 | - $cache_sistem_lib->set_cache( $cache_id, $posts_data ); |
|
118 | - $feed_articles = $posts_data; |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - return $feed_articles; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * Add the `utm` parameter for GA. |
|
127 | - * |
|
128 | - * @param string $url The URL. |
|
129 | - * |
|
130 | - * @return string The URL with the `utm` parameter prepended by `&` or by `?`. |
|
131 | - * @since 3.19.0 |
|
132 | - */ |
|
133 | - private static function add_utm_parameter( $url ) { |
|
134 | - |
|
135 | - if ( false === strpos( $url, '?' ) ) { |
|
136 | - return $url . '?utm=wl_dash'; |
|
137 | - } |
|
138 | - |
|
139 | - return $url . '&utm=wl_dash'; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Ajax call for more latest news. |
|
144 | - * |
|
145 | - * @uses https://codex.wordpress.org/Function_Reference/wp_send_json_success |
|
146 | - */ |
|
147 | - public function ajax_get_latest_news() { |
|
148 | - // Get wordlift articles |
|
149 | - $more_posts_link_id = isset( $_POST['more_posts_link_id'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['more_posts_link_id'] ) ) : '';//phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
150 | - $start_position = explode( '_', $more_posts_link_id ); |
|
151 | - $data = $this->get_last_wordlift_articles( $start_position[ count( $start_position ) - 1 ] ); |
|
152 | - |
|
153 | - // Return response as json object |
|
154 | - wp_send_json_success( $data ); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Add latest news widget to the administration dashboard. |
|
159 | - */ |
|
160 | - public function add_dashboard_latest_news_widget() { |
|
161 | - |
|
162 | - /** |
|
163 | - * Filter name: wl_feature__enable__wordlift-news |
|
164 | - * Feature flag to enable / disable news widget. |
|
165 | - * |
|
166 | - * @since 3.30.0 |
|
167 | - */ |
|
168 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
169 | - if ( apply_filters( 'wl_feature__enable__wordlift-news', true ) ) { |
|
170 | - |
|
171 | - wp_add_dashboard_widget( |
|
172 | - 'wordlift-dashboard-latest-news-widget', |
|
173 | - 'Latest WordLift News', |
|
174 | - array( |
|
175 | - $this, |
|
176 | - 'render', |
|
177 | - ) |
|
178 | - ); |
|
179 | - } |
|
180 | - } |
|
23 | + /** |
|
24 | + * Add needed hooks for the latest news widget. |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + add_action( |
|
28 | + 'wp_ajax_wordlift_get_latest_news', |
|
29 | + array( |
|
30 | + $this, |
|
31 | + 'ajax_get_latest_news', |
|
32 | + ) |
|
33 | + ); |
|
34 | + add_action( |
|
35 | + 'wp_dashboard_setup', |
|
36 | + array( |
|
37 | + $this, |
|
38 | + 'add_dashboard_latest_news_widget', |
|
39 | + ) |
|
40 | + ); |
|
41 | + |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * Return latest news html. |
|
46 | + */ |
|
47 | + public function render() { |
|
48 | + |
|
49 | + wp_enqueue_script( 'wl-admin-dashboard', plugin_dir_url( __DIR__ ) . 'admin/js/wordlift-admin-dashboard.js', array( 'jquery' ), '3.22.0', true ); |
|
50 | + |
|
51 | + include plugin_dir_path( __FILE__ ) . 'partials/wordlift-admin-news-widget.php'; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Returns latest news data filtered by $start_position. |
|
56 | + * |
|
57 | + * @param int $start_position (news array key start position). |
|
58 | + * |
|
59 | + * @return array Latest posts data. |
|
60 | + */ |
|
61 | + public function get_last_wordlift_articles( $start_position = 0 ) { |
|
62 | + $feed_articles = $this->get_wordlift_articles_data(); |
|
63 | + |
|
64 | + // Filter articles by $start_position |
|
65 | + if ( ! empty( $feed_articles ) ) { |
|
66 | + return array( |
|
67 | + 'posts_data' => array_slice( $feed_articles, $start_position, 3 ), |
|
68 | + 'count' => count( $feed_articles ), |
|
69 | + 'start_position' => $start_position, |
|
70 | + ); |
|
71 | + } |
|
72 | + |
|
73 | + return false; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Returns latest news array data. |
|
78 | + * |
|
79 | + * @uses https://codex.wordpress.org/Function_Reference/fetch_feed |
|
80 | + * @uses https://codex.wordpress.org/Function_Reference/get_locale |
|
81 | + * |
|
82 | + * @param int $articles_number (articles total number). |
|
83 | + * |
|
84 | + * @return array Latest $articles_number feed posts. |
|
85 | + */ |
|
86 | + public function get_wordlift_articles_data( $articles_number = 10 ) { |
|
87 | + // Init cache class |
|
88 | + $cache_sistem_lib = new Wordlift_File_Cache_Service( WL_TEMP_DIR . 'articles/' ); |
|
89 | + $locale = get_locale(); |
|
90 | + $cache_id = 'news_' . gmdate( 'Y_m_d' ) . '_' . $locale; |
|
91 | + $posts_data = array(); |
|
92 | + |
|
93 | + // Get latest articles from cache |
|
94 | + $feed_articles = $cache_sistem_lib->get_cache( $cache_id ); |
|
95 | + if ( false === $feed_articles ) { |
|
96 | + // Check WordPress installation language to define articles rss url |
|
97 | + $feed_uri = ( 'it_IT' === $locale ) ? 'https://wordlift.io/blog/it/feed/' : 'https://wordlift.io/blog/en/feed/'; |
|
98 | + |
|
99 | + // Get rss feed data, the response is cached by default for 12 hours |
|
100 | + $feed = fetch_feed( $feed_uri ); |
|
101 | + if ( ! is_wp_error( $feed ) ) { |
|
102 | + // Build an array of requested $articles_number, starting with element 0 |
|
103 | + $feed_articles = $feed->get_items( 0, $articles_number ); |
|
104 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
105 | + foreach ( $feed_articles as $key => $item ) { |
|
106 | + $data = array( |
|
107 | + // fetch_feed will return the title html decoded. |
|
108 | + 'post_title' => $item->get_title(), |
|
109 | + 'post_date' => $item->get_date( 'j F Y | g:i a' ), |
|
110 | + 'post_url' => self::add_utm_parameter( $item->get_permalink() ), |
|
111 | + // fetch_feed will return the description html (not decoded). |
|
112 | + 'post_description' => $item->get_description(), |
|
113 | + ); |
|
114 | + array_push( $posts_data, $data ); |
|
115 | + } |
|
116 | + // Set articles in cache. |
|
117 | + $cache_sistem_lib->set_cache( $cache_id, $posts_data ); |
|
118 | + $feed_articles = $posts_data; |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + return $feed_articles; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * Add the `utm` parameter for GA. |
|
127 | + * |
|
128 | + * @param string $url The URL. |
|
129 | + * |
|
130 | + * @return string The URL with the `utm` parameter prepended by `&` or by `?`. |
|
131 | + * @since 3.19.0 |
|
132 | + */ |
|
133 | + private static function add_utm_parameter( $url ) { |
|
134 | + |
|
135 | + if ( false === strpos( $url, '?' ) ) { |
|
136 | + return $url . '?utm=wl_dash'; |
|
137 | + } |
|
138 | + |
|
139 | + return $url . '&utm=wl_dash'; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Ajax call for more latest news. |
|
144 | + * |
|
145 | + * @uses https://codex.wordpress.org/Function_Reference/wp_send_json_success |
|
146 | + */ |
|
147 | + public function ajax_get_latest_news() { |
|
148 | + // Get wordlift articles |
|
149 | + $more_posts_link_id = isset( $_POST['more_posts_link_id'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['more_posts_link_id'] ) ) : '';//phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
150 | + $start_position = explode( '_', $more_posts_link_id ); |
|
151 | + $data = $this->get_last_wordlift_articles( $start_position[ count( $start_position ) - 1 ] ); |
|
152 | + |
|
153 | + // Return response as json object |
|
154 | + wp_send_json_success( $data ); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Add latest news widget to the administration dashboard. |
|
159 | + */ |
|
160 | + public function add_dashboard_latest_news_widget() { |
|
161 | + |
|
162 | + /** |
|
163 | + * Filter name: wl_feature__enable__wordlift-news |
|
164 | + * Feature flag to enable / disable news widget. |
|
165 | + * |
|
166 | + * @since 3.30.0 |
|
167 | + */ |
|
168 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
169 | + if ( apply_filters( 'wl_feature__enable__wordlift-news', true ) ) { |
|
170 | + |
|
171 | + wp_add_dashboard_widget( |
|
172 | + 'wordlift-dashboard-latest-news-widget', |
|
173 | + 'Latest WordLift News', |
|
174 | + array( |
|
175 | + $this, |
|
176 | + 'render', |
|
177 | + ) |
|
178 | + ); |
|
179 | + } |
|
180 | + } |
|
181 | 181 | |
182 | 182 | } |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function render() { |
48 | 48 | |
49 | - wp_enqueue_script( 'wl-admin-dashboard', plugin_dir_url( __DIR__ ) . 'admin/js/wordlift-admin-dashboard.js', array( 'jquery' ), '3.22.0', true ); |
|
49 | + wp_enqueue_script('wl-admin-dashboard', plugin_dir_url(__DIR__).'admin/js/wordlift-admin-dashboard.js', array('jquery'), '3.22.0', true); |
|
50 | 50 | |
51 | - include plugin_dir_path( __FILE__ ) . 'partials/wordlift-admin-news-widget.php'; |
|
51 | + include plugin_dir_path(__FILE__).'partials/wordlift-admin-news-widget.php'; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
@@ -58,14 +58,14 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return array Latest posts data. |
60 | 60 | */ |
61 | - public function get_last_wordlift_articles( $start_position = 0 ) { |
|
61 | + public function get_last_wordlift_articles($start_position = 0) { |
|
62 | 62 | $feed_articles = $this->get_wordlift_articles_data(); |
63 | 63 | |
64 | 64 | // Filter articles by $start_position |
65 | - if ( ! empty( $feed_articles ) ) { |
|
65 | + if ( ! empty($feed_articles)) { |
|
66 | 66 | return array( |
67 | - 'posts_data' => array_slice( $feed_articles, $start_position, 3 ), |
|
68 | - 'count' => count( $feed_articles ), |
|
67 | + 'posts_data' => array_slice($feed_articles, $start_position, 3), |
|
68 | + 'count' => count($feed_articles), |
|
69 | 69 | 'start_position' => $start_position, |
70 | 70 | ); |
71 | 71 | } |
@@ -83,38 +83,38 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @return array Latest $articles_number feed posts. |
85 | 85 | */ |
86 | - public function get_wordlift_articles_data( $articles_number = 10 ) { |
|
86 | + public function get_wordlift_articles_data($articles_number = 10) { |
|
87 | 87 | // Init cache class |
88 | - $cache_sistem_lib = new Wordlift_File_Cache_Service( WL_TEMP_DIR . 'articles/' ); |
|
88 | + $cache_sistem_lib = new Wordlift_File_Cache_Service(WL_TEMP_DIR.'articles/'); |
|
89 | 89 | $locale = get_locale(); |
90 | - $cache_id = 'news_' . gmdate( 'Y_m_d' ) . '_' . $locale; |
|
90 | + $cache_id = 'news_'.gmdate('Y_m_d').'_'.$locale; |
|
91 | 91 | $posts_data = array(); |
92 | 92 | |
93 | 93 | // Get latest articles from cache |
94 | - $feed_articles = $cache_sistem_lib->get_cache( $cache_id ); |
|
95 | - if ( false === $feed_articles ) { |
|
94 | + $feed_articles = $cache_sistem_lib->get_cache($cache_id); |
|
95 | + if (false === $feed_articles) { |
|
96 | 96 | // Check WordPress installation language to define articles rss url |
97 | - $feed_uri = ( 'it_IT' === $locale ) ? 'https://wordlift.io/blog/it/feed/' : 'https://wordlift.io/blog/en/feed/'; |
|
97 | + $feed_uri = ('it_IT' === $locale) ? 'https://wordlift.io/blog/it/feed/' : 'https://wordlift.io/blog/en/feed/'; |
|
98 | 98 | |
99 | 99 | // Get rss feed data, the response is cached by default for 12 hours |
100 | - $feed = fetch_feed( $feed_uri ); |
|
101 | - if ( ! is_wp_error( $feed ) ) { |
|
100 | + $feed = fetch_feed($feed_uri); |
|
101 | + if ( ! is_wp_error($feed)) { |
|
102 | 102 | // Build an array of requested $articles_number, starting with element 0 |
103 | - $feed_articles = $feed->get_items( 0, $articles_number ); |
|
103 | + $feed_articles = $feed->get_items(0, $articles_number); |
|
104 | 104 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
105 | - foreach ( $feed_articles as $key => $item ) { |
|
105 | + foreach ($feed_articles as $key => $item) { |
|
106 | 106 | $data = array( |
107 | 107 | // fetch_feed will return the title html decoded. |
108 | 108 | 'post_title' => $item->get_title(), |
109 | - 'post_date' => $item->get_date( 'j F Y | g:i a' ), |
|
110 | - 'post_url' => self::add_utm_parameter( $item->get_permalink() ), |
|
109 | + 'post_date' => $item->get_date('j F Y | g:i a'), |
|
110 | + 'post_url' => self::add_utm_parameter($item->get_permalink()), |
|
111 | 111 | // fetch_feed will return the description html (not decoded). |
112 | 112 | 'post_description' => $item->get_description(), |
113 | 113 | ); |
114 | - array_push( $posts_data, $data ); |
|
114 | + array_push($posts_data, $data); |
|
115 | 115 | } |
116 | 116 | // Set articles in cache. |
117 | - $cache_sistem_lib->set_cache( $cache_id, $posts_data ); |
|
117 | + $cache_sistem_lib->set_cache($cache_id, $posts_data); |
|
118 | 118 | $feed_articles = $posts_data; |
119 | 119 | } |
120 | 120 | } |
@@ -130,13 +130,13 @@ discard block |
||
130 | 130 | * @return string The URL with the `utm` parameter prepended by `&` or by `?`. |
131 | 131 | * @since 3.19.0 |
132 | 132 | */ |
133 | - private static function add_utm_parameter( $url ) { |
|
133 | + private static function add_utm_parameter($url) { |
|
134 | 134 | |
135 | - if ( false === strpos( $url, '?' ) ) { |
|
136 | - return $url . '?utm=wl_dash'; |
|
135 | + if (false === strpos($url, '?')) { |
|
136 | + return $url.'?utm=wl_dash'; |
|
137 | 137 | } |
138 | 138 | |
139 | - return $url . '&utm=wl_dash'; |
|
139 | + return $url.'&utm=wl_dash'; |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -146,12 +146,12 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public function ajax_get_latest_news() { |
148 | 148 | // Get wordlift articles |
149 | - $more_posts_link_id = isset( $_POST['more_posts_link_id'] ) ? sanitize_text_field( wp_unslash( (string) $_POST['more_posts_link_id'] ) ) : '';//phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
150 | - $start_position = explode( '_', $more_posts_link_id ); |
|
151 | - $data = $this->get_last_wordlift_articles( $start_position[ count( $start_position ) - 1 ] ); |
|
149 | + $more_posts_link_id = isset($_POST['more_posts_link_id']) ? sanitize_text_field(wp_unslash((string) $_POST['more_posts_link_id'])) : ''; //phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
150 | + $start_position = explode('_', $more_posts_link_id); |
|
151 | + $data = $this->get_last_wordlift_articles($start_position[count($start_position) - 1]); |
|
152 | 152 | |
153 | 153 | // Return response as json object |
154 | - wp_send_json_success( $data ); |
|
154 | + wp_send_json_success($data); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @since 3.30.0 |
167 | 167 | */ |
168 | 168 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
169 | - if ( apply_filters( 'wl_feature__enable__wordlift-news', true ) ) { |
|
169 | + if (apply_filters('wl_feature__enable__wordlift-news', true)) { |
|
170 | 170 | |
171 | 171 | wp_add_dashboard_widget( |
172 | 172 | 'wordlift-dashboard-latest-news-widget', |
@@ -9,11 +9,11 @@ discard block |
||
9 | 9 | * Loads the buttons in TinyMCE. |
10 | 10 | */ |
11 | 11 | function wl_admin_shortcode_buttons() { |
12 | - // Only add hooks when the current user has permissions AND is in Rich Text editor mode |
|
13 | - if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) { |
|
14 | - // add_filter( 'mce_external_plugins', 'wl_admin_shortcode_buttons_register_tinymce_javascript' ); |
|
15 | - add_filter( 'mce_buttons', 'wl_admin_shortcode_register_buttons' ); |
|
16 | - } |
|
12 | + // Only add hooks when the current user has permissions AND is in Rich Text editor mode |
|
13 | + if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) { |
|
14 | + // add_filter( 'mce_external_plugins', 'wl_admin_shortcode_buttons_register_tinymce_javascript' ); |
|
15 | + add_filter( 'mce_buttons', 'wl_admin_shortcode_register_buttons' ); |
|
16 | + } |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -24,9 +24,9 @@ discard block |
||
24 | 24 | * @return array The buttons array including the *wl_shortcodes_menu*. |
25 | 25 | */ |
26 | 26 | function wl_admin_shortcode_register_buttons( $buttons ) { |
27 | - array_push( $buttons, 'wl_shortcodes_menu' ); |
|
27 | + array_push( $buttons, 'wl_shortcodes_menu' ); |
|
28 | 28 | |
29 | - return $buttons; |
|
29 | + return $buttons; |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | // init process for button control |
@@ -10,9 +10,9 @@ discard block |
||
10 | 10 | */ |
11 | 11 | function wl_admin_shortcode_buttons() { |
12 | 12 | // Only add hooks when the current user has permissions AND is in Rich Text editor mode |
13 | - if ( ( current_user_can( 'edit_posts' ) || current_user_can( 'edit_pages' ) ) && get_user_option( 'rich_editing' ) ) { |
|
13 | + if ((current_user_can('edit_posts') || current_user_can('edit_pages')) && get_user_option('rich_editing')) { |
|
14 | 14 | // add_filter( 'mce_external_plugins', 'wl_admin_shortcode_buttons_register_tinymce_javascript' ); |
15 | - add_filter( 'mce_buttons', 'wl_admin_shortcode_register_buttons' ); |
|
15 | + add_filter('mce_buttons', 'wl_admin_shortcode_register_buttons'); |
|
16 | 16 | } |
17 | 17 | } |
18 | 18 | |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return array The buttons array including the *wl_shortcodes_menu*. |
25 | 25 | */ |
26 | -function wl_admin_shortcode_register_buttons( $buttons ) { |
|
27 | - array_push( $buttons, 'wl_shortcodes_menu' ); |
|
26 | +function wl_admin_shortcode_register_buttons($buttons) { |
|
27 | + array_push($buttons, 'wl_shortcodes_menu'); |
|
28 | 28 | |
29 | 29 | return $buttons; |
30 | 30 | } |
31 | 31 | |
32 | 32 | // init process for button control |
33 | -add_action( 'admin_init', 'wl_admin_shortcode_buttons' ); |
|
33 | +add_action('admin_init', 'wl_admin_shortcode_buttons'); |