@@ -1,4 +1,4 @@ |
||
1 | 1 | <?php return array( |
2 | - 'dependencies' => array( 'react', 'react-dom', 'wp-polyfill' ), |
|
3 | - 'version' => '0df9b7715acd39056c8ca1e24dedb4b1', |
|
2 | + 'dependencies' => array( 'react', 'react-dom', 'wp-polyfill' ), |
|
3 | + 'version' => '0df9b7715acd39056c8ca1e24dedb4b1', |
|
4 | 4 | ); |
@@ -1,4 +1,4 @@ |
||
1 | 1 | <?php return array( |
2 | - 'dependencies' => array( 'react', 'react-dom', 'wp-polyfill' ), |
|
2 | + 'dependencies' => array('react', 'react-dom', 'wp-polyfill'), |
|
3 | 3 | 'version' => '0df9b7715acd39056c8ca1e24dedb4b1', |
4 | 4 | ); |
@@ -1,4 +1,4 @@ |
||
1 | 1 | <?php return array( |
2 | - 'dependencies' => array( 'wp-polyfill' ), |
|
3 | - 'version' => 'dc74b50aef496ca5fcca1eda880e38a1', |
|
2 | + 'dependencies' => array( 'wp-polyfill' ), |
|
3 | + 'version' => 'dc74b50aef496ca5fcca1eda880e38a1', |
|
4 | 4 | ); |
@@ -1,4 +1,4 @@ |
||
1 | 1 | <?php return array( |
2 | - 'dependencies' => array( 'wp-polyfill' ), |
|
2 | + 'dependencies' => array('wp-polyfill'), |
|
3 | 3 | 'version' => 'dc74b50aef496ca5fcca1eda880e38a1', |
4 | 4 | ); |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | * @subpackage Wordlift/includes |
11 | 11 | */ |
12 | 12 | if ( ! class_exists( 'Walker_Category_Checklist' ) ) { |
13 | - require_once ABSPATH . 'wp-admin/includes/template.php'; |
|
13 | + require_once ABSPATH . 'wp-admin/includes/template.php'; |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | /** |
@@ -24,113 +24,113 @@ discard block |
||
24 | 24 | // phpcs:ignore Generic.Classes.DuplicateClassName.Found |
25 | 25 | class Wordlift_Entity_Types_Taxonomy_Walker extends Walker_Category_Checklist { |
26 | 26 | |
27 | - /** |
|
28 | - * Entity taxonomy metabox must show exclusive options, no checkboxes. |
|
29 | - * |
|
30 | - * @since 3.1.0 |
|
31 | - * |
|
32 | - * @param $args { |
|
33 | - * An array of arguments. |
|
34 | - * |
|
35 | - * @type string $taxonomy The taxonomy name. |
|
36 | - * } |
|
37 | - * |
|
38 | - * @return array An array of arguments, with this walker in case the taxonomy is the Entity Type taxonomy. |
|
39 | - */ |
|
40 | - public function terms_checklist_args( $args ) { |
|
41 | - |
|
42 | - if ( ! isset( $args['taxonomy'] ) || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) { |
|
43 | - return $args; |
|
44 | - } |
|
45 | - |
|
46 | - // We override the way WP prints the taxonomy metabox HTML. |
|
47 | - $args['walker'] = $this; |
|
48 | - $args['checked_ontop'] = false; |
|
49 | - |
|
50 | - return $args; |
|
51 | - |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Change checkboxes to radios. |
|
56 | - * |
|
57 | - * $max_depth = -1 means flatly display every element. |
|
58 | - * $max_depth = 0 means display all levels. |
|
59 | - * $max_depth > 0 specifies the number of display levels. |
|
60 | - * |
|
61 | - * @since 3.1.0 |
|
62 | - * |
|
63 | - * @param array $elements An array of elements. |
|
64 | - * @param int $max_depth The maximum hierarchical depth. |
|
65 | - * |
|
66 | - * @param array $args Additional arguments. |
|
67 | - * |
|
68 | - * @return string The hierarchical item output. |
|
69 | - */ |
|
70 | - public function walk( $elements, $max_depth, $args = array() ) { |
|
71 | - |
|
72 | - // `max_depth` force to -1 to display a flat taxonomy. |
|
73 | - // |
|
74 | - // See https://github.com/insideout10/wordlift-plugin/issues/305 |
|
75 | - $output = parent::walk( $elements, - 1, $args ); |
|
76 | - |
|
77 | - $output = str_replace( |
|
78 | - array( 'type="checkbox"', "type='checkbox'" ), |
|
79 | - array( 'type="radio"', "type='radio'" ), |
|
80 | - $output |
|
81 | - ); |
|
82 | - |
|
83 | - return $output; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Start the element output, output nothing in case of article term. |
|
88 | - * |
|
89 | - * @since 3.15.0 |
|
90 | - * |
|
91 | - * @param string $output Passed by reference. Used to append additional content. |
|
92 | - * @param object $category The current term object. |
|
93 | - * @param int $depth Depth of the term in reference to parents. Default 0. |
|
94 | - * @param array $args An array of arguments. @see wp_terms_checklist() |
|
95 | - * @param int $id ID of the current term. |
|
96 | - */ |
|
97 | - public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { |
|
98 | - global $post; |
|
99 | - |
|
100 | - if ( ! isset( $post ) ) { |
|
101 | - return; |
|
102 | - } |
|
103 | - |
|
104 | - if ( Wordlift_Entity_Service::TYPE_NAME !== $post->post_type |
|
105 | - || 'article' !== $category->slug |
|
106 | - || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) { |
|
107 | - parent::start_el( $output, $category, $depth, $args, $id ); |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * End the element output, output nothing in case of article term. |
|
113 | - * |
|
114 | - * @since 3.15.0 |
|
115 | - * |
|
116 | - * @param string $output Passed by reference. Used to append additional content. |
|
117 | - * @param object $category The current term object. |
|
118 | - * @param int $depth Depth of the term in reference to parents. Default 0. |
|
119 | - * @param array $args An array of arguments. @see wp_terms_checklist() |
|
120 | - */ |
|
121 | - public function end_el( &$output, $category, $depth = 0, $args = array() ) { |
|
122 | - global $post; |
|
123 | - |
|
124 | - if ( ! isset( $post ) ) { |
|
125 | - return; |
|
126 | - } |
|
127 | - |
|
128 | - if ( Wordlift_Entity_Service::TYPE_NAME !== $post->post_type |
|
129 | - || 'article' !== $category->slug |
|
130 | - || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) { |
|
131 | - parent::end_el( $output, $category, $depth, $args ); |
|
132 | - } |
|
133 | - |
|
134 | - } |
|
27 | + /** |
|
28 | + * Entity taxonomy metabox must show exclusive options, no checkboxes. |
|
29 | + * |
|
30 | + * @since 3.1.0 |
|
31 | + * |
|
32 | + * @param $args { |
|
33 | + * An array of arguments. |
|
34 | + * |
|
35 | + * @type string $taxonomy The taxonomy name. |
|
36 | + * } |
|
37 | + * |
|
38 | + * @return array An array of arguments, with this walker in case the taxonomy is the Entity Type taxonomy. |
|
39 | + */ |
|
40 | + public function terms_checklist_args( $args ) { |
|
41 | + |
|
42 | + if ( ! isset( $args['taxonomy'] ) || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) { |
|
43 | + return $args; |
|
44 | + } |
|
45 | + |
|
46 | + // We override the way WP prints the taxonomy metabox HTML. |
|
47 | + $args['walker'] = $this; |
|
48 | + $args['checked_ontop'] = false; |
|
49 | + |
|
50 | + return $args; |
|
51 | + |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Change checkboxes to radios. |
|
56 | + * |
|
57 | + * $max_depth = -1 means flatly display every element. |
|
58 | + * $max_depth = 0 means display all levels. |
|
59 | + * $max_depth > 0 specifies the number of display levels. |
|
60 | + * |
|
61 | + * @since 3.1.0 |
|
62 | + * |
|
63 | + * @param array $elements An array of elements. |
|
64 | + * @param int $max_depth The maximum hierarchical depth. |
|
65 | + * |
|
66 | + * @param array $args Additional arguments. |
|
67 | + * |
|
68 | + * @return string The hierarchical item output. |
|
69 | + */ |
|
70 | + public function walk( $elements, $max_depth, $args = array() ) { |
|
71 | + |
|
72 | + // `max_depth` force to -1 to display a flat taxonomy. |
|
73 | + // |
|
74 | + // See https://github.com/insideout10/wordlift-plugin/issues/305 |
|
75 | + $output = parent::walk( $elements, - 1, $args ); |
|
76 | + |
|
77 | + $output = str_replace( |
|
78 | + array( 'type="checkbox"', "type='checkbox'" ), |
|
79 | + array( 'type="radio"', "type='radio'" ), |
|
80 | + $output |
|
81 | + ); |
|
82 | + |
|
83 | + return $output; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Start the element output, output nothing in case of article term. |
|
88 | + * |
|
89 | + * @since 3.15.0 |
|
90 | + * |
|
91 | + * @param string $output Passed by reference. Used to append additional content. |
|
92 | + * @param object $category The current term object. |
|
93 | + * @param int $depth Depth of the term in reference to parents. Default 0. |
|
94 | + * @param array $args An array of arguments. @see wp_terms_checklist() |
|
95 | + * @param int $id ID of the current term. |
|
96 | + */ |
|
97 | + public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { |
|
98 | + global $post; |
|
99 | + |
|
100 | + if ( ! isset( $post ) ) { |
|
101 | + return; |
|
102 | + } |
|
103 | + |
|
104 | + if ( Wordlift_Entity_Service::TYPE_NAME !== $post->post_type |
|
105 | + || 'article' !== $category->slug |
|
106 | + || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) { |
|
107 | + parent::start_el( $output, $category, $depth, $args, $id ); |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * End the element output, output nothing in case of article term. |
|
113 | + * |
|
114 | + * @since 3.15.0 |
|
115 | + * |
|
116 | + * @param string $output Passed by reference. Used to append additional content. |
|
117 | + * @param object $category The current term object. |
|
118 | + * @param int $depth Depth of the term in reference to parents. Default 0. |
|
119 | + * @param array $args An array of arguments. @see wp_terms_checklist() |
|
120 | + */ |
|
121 | + public function end_el( &$output, $category, $depth = 0, $args = array() ) { |
|
122 | + global $post; |
|
123 | + |
|
124 | + if ( ! isset( $post ) ) { |
|
125 | + return; |
|
126 | + } |
|
127 | + |
|
128 | + if ( Wordlift_Entity_Service::TYPE_NAME !== $post->post_type |
|
129 | + || 'article' !== $category->slug |
|
130 | + || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) { |
|
131 | + parent::end_el( $output, $category, $depth, $args ); |
|
132 | + } |
|
133 | + |
|
134 | + } |
|
135 | 135 | |
136 | 136 | } |
@@ -9,8 +9,8 @@ discard block |
||
9 | 9 | * @package Wordlift |
10 | 10 | * @subpackage Wordlift/includes |
11 | 11 | */ |
12 | -if ( ! class_exists( 'Walker_Category_Checklist' ) ) { |
|
13 | - require_once ABSPATH . 'wp-admin/includes/template.php'; |
|
12 | +if ( ! class_exists('Walker_Category_Checklist')) { |
|
13 | + require_once ABSPATH.'wp-admin/includes/template.php'; |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | /** |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @return array An array of arguments, with this walker in case the taxonomy is the Entity Type taxonomy. |
39 | 39 | */ |
40 | - public function terms_checklist_args( $args ) { |
|
40 | + public function terms_checklist_args($args) { |
|
41 | 41 | |
42 | - if ( ! isset( $args['taxonomy'] ) || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) { |
|
42 | + if ( ! isset($args['taxonomy']) || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy']) { |
|
43 | 43 | return $args; |
44 | 44 | } |
45 | 45 | |
@@ -67,16 +67,16 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @return string The hierarchical item output. |
69 | 69 | */ |
70 | - public function walk( $elements, $max_depth, $args = array() ) { |
|
70 | + public function walk($elements, $max_depth, $args = array()) { |
|
71 | 71 | |
72 | 72 | // `max_depth` force to -1 to display a flat taxonomy. |
73 | 73 | // |
74 | 74 | // See https://github.com/insideout10/wordlift-plugin/issues/305 |
75 | - $output = parent::walk( $elements, - 1, $args ); |
|
75 | + $output = parent::walk($elements, - 1, $args); |
|
76 | 76 | |
77 | 77 | $output = str_replace( |
78 | - array( 'type="checkbox"', "type='checkbox'" ), |
|
79 | - array( 'type="radio"', "type='radio'" ), |
|
78 | + array('type="checkbox"', "type='checkbox'"), |
|
79 | + array('type="radio"', "type='radio'"), |
|
80 | 80 | $output |
81 | 81 | ); |
82 | 82 | |
@@ -94,17 +94,17 @@ discard block |
||
94 | 94 | * @param array $args An array of arguments. @see wp_terms_checklist() |
95 | 95 | * @param int $id ID of the current term. |
96 | 96 | */ |
97 | - public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) { |
|
97 | + public function start_el(&$output, $category, $depth = 0, $args = array(), $id = 0) { |
|
98 | 98 | global $post; |
99 | 99 | |
100 | - if ( ! isset( $post ) ) { |
|
100 | + if ( ! isset($post)) { |
|
101 | 101 | return; |
102 | 102 | } |
103 | 103 | |
104 | - if ( Wordlift_Entity_Service::TYPE_NAME !== $post->post_type |
|
104 | + if (Wordlift_Entity_Service::TYPE_NAME !== $post->post_type |
|
105 | 105 | || 'article' !== $category->slug |
106 | - || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) { |
|
107 | - parent::start_el( $output, $category, $depth, $args, $id ); |
|
106 | + || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy']) { |
|
107 | + parent::start_el($output, $category, $depth, $args, $id); |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
@@ -118,17 +118,17 @@ discard block |
||
118 | 118 | * @param int $depth Depth of the term in reference to parents. Default 0. |
119 | 119 | * @param array $args An array of arguments. @see wp_terms_checklist() |
120 | 120 | */ |
121 | - public function end_el( &$output, $category, $depth = 0, $args = array() ) { |
|
121 | + public function end_el(&$output, $category, $depth = 0, $args = array()) { |
|
122 | 122 | global $post; |
123 | 123 | |
124 | - if ( ! isset( $post ) ) { |
|
124 | + if ( ! isset($post)) { |
|
125 | 125 | return; |
126 | 126 | } |
127 | 127 | |
128 | - if ( Wordlift_Entity_Service::TYPE_NAME !== $post->post_type |
|
128 | + if (Wordlift_Entity_Service::TYPE_NAME !== $post->post_type |
|
129 | 129 | || 'article' !== $category->slug |
130 | - || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy'] ) { |
|
131 | - parent::end_el( $output, $category, $depth, $args ); |
|
130 | + || Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME !== $args['taxonomy']) { |
|
131 | + parent::end_el($output, $category, $depth, $args); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | } |
@@ -20,131 +20,131 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class Wordlift_Admin_Post_Edit_Page { |
22 | 22 | |
23 | - /** |
|
24 | - * Constants to be used instead of text inside FAQ |
|
25 | - * helper methods. |
|
26 | - */ |
|
27 | - const GUTENBERG = 'gutenberg'; |
|
28 | - const TINY_MCE = 'tiny_mce'; |
|
29 | - const FAQ_LIST_BOX_ID = 'wl-faq-meta-list-box'; |
|
30 | - |
|
31 | - /** Constant to be used for translation domain */ |
|
32 | - const WORDLIFT_TEXT_DOMAIN = 'wordlift'; |
|
33 | - |
|
34 | - /** |
|
35 | - * The {@link Wordlift} plugin instance. |
|
36 | - * |
|
37 | - * @since 3.11.0 |
|
38 | - * |
|
39 | - * @var \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
40 | - */ |
|
41 | - private $plugin; |
|
42 | - |
|
43 | - /** |
|
44 | - * A {@link Wordlift_Log_Service} instance. |
|
45 | - * |
|
46 | - * @since 3.15.4 |
|
47 | - * |
|
48 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
49 | - */ |
|
50 | - private $log; |
|
51 | - |
|
52 | - /** |
|
53 | - * Create the {@link Wordlift_Admin_Post_Edit_Page} instance. |
|
54 | - * |
|
55 | - * @param \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
56 | - * |
|
57 | - * @since 3.11.0 |
|
58 | - */ |
|
59 | - public function __construct( $plugin ) { |
|
60 | - |
|
61 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
62 | - |
|
63 | - add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_scripts_gutenberg' ) ); |
|
64 | - |
|
65 | - // Bail out if we're in the UX Builder editor. |
|
66 | - if ( $this->is_ux_builder_editor() ) { |
|
67 | - $this->log->info( 'WordLift will not show, since we are in UX Builder editor.' ); |
|
68 | - |
|
69 | - return; |
|
70 | - } |
|
71 | - |
|
72 | - // Define the callbacks. |
|
73 | - $callback = array( $this, 'enqueue_scripts' ); |
|
74 | - // Set a hook to enqueue scripts only when the edit page is displayed. |
|
75 | - add_action( 'admin_print_scripts-post.php', $callback ); |
|
76 | - add_action( 'admin_print_scripts-post-new.php', $callback ); |
|
77 | - |
|
78 | - $this->plugin = $plugin; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Check whether the current post opens with G'berg or not. |
|
83 | - * |
|
84 | - * @return bool True if G'berg is used otherwise false. |
|
85 | - * @since 3.22.3 |
|
86 | - */ |
|
87 | - public function is_gutenberg_page() { |
|
88 | - if ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) { |
|
89 | - // The Gutenberg plugin is on. |
|
90 | - return true; |
|
91 | - } |
|
92 | - |
|
93 | - $current_screen = get_current_screen(); |
|
94 | - if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) { |
|
95 | - // Gutenberg page on 5+. |
|
96 | - return true; |
|
97 | - } |
|
98 | - |
|
99 | - return false; |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Check if we're in UX builder. |
|
104 | - * |
|
105 | - * @see https://github.com/insideout10/wordlift-plugin/issues/691 |
|
106 | - * |
|
107 | - * @since 3.15.4 |
|
108 | - * |
|
109 | - * @return bool True if we're in UX builder, otherwise false. |
|
110 | - */ |
|
111 | - private function is_ux_builder_editor() { |
|
112 | - |
|
113 | - return function_exists( 'ux_builder_is_editor' ) |
|
114 | - && ux_builder_is_editor(); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Enqueue scripts and styles for the edit page. |
|
119 | - * |
|
120 | - * @since 3.11.0 |
|
121 | - */ |
|
122 | - public function enqueue_scripts() { |
|
123 | - |
|
124 | - // Dequeue potentially conflicting ontrapages angular scripts which any *are not* used on the edit screen. |
|
125 | - // |
|
126 | - // @see https://github.com/insideout10/wordlift-plugin/issues/832 |
|
127 | - wp_dequeue_script( 'ontrapagesAngular' ); |
|
128 | - wp_dequeue_script( 'ontrapagesApp' ); |
|
129 | - wp_dequeue_script( 'ontrapagesController' ); |
|
130 | - |
|
131 | - // Bail out if this is G'berg. |
|
132 | - if ( $this->is_gutenberg_page() ) { |
|
133 | - return; |
|
134 | - } |
|
135 | - |
|
136 | - // If Gutenberg is enabled for the post, do not load the legacy edit.js. |
|
137 | - if ( function_exists( 'use_block_editor_for_post' ) && use_block_editor_for_post( get_post() ) ) { |
|
138 | - return; |
|
139 | - } |
|
140 | - |
|
141 | - // Bail out if classification sidebar is not enabled via hook |
|
142 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
143 | - if ( ! apply_filters( 'wl_feature__enable__classification-sidebar', true ) ) { |
|
144 | - return; |
|
145 | - } |
|
146 | - |
|
147 | - /* |
|
23 | + /** |
|
24 | + * Constants to be used instead of text inside FAQ |
|
25 | + * helper methods. |
|
26 | + */ |
|
27 | + const GUTENBERG = 'gutenberg'; |
|
28 | + const TINY_MCE = 'tiny_mce'; |
|
29 | + const FAQ_LIST_BOX_ID = 'wl-faq-meta-list-box'; |
|
30 | + |
|
31 | + /** Constant to be used for translation domain */ |
|
32 | + const WORDLIFT_TEXT_DOMAIN = 'wordlift'; |
|
33 | + |
|
34 | + /** |
|
35 | + * The {@link Wordlift} plugin instance. |
|
36 | + * |
|
37 | + * @since 3.11.0 |
|
38 | + * |
|
39 | + * @var \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
40 | + */ |
|
41 | + private $plugin; |
|
42 | + |
|
43 | + /** |
|
44 | + * A {@link Wordlift_Log_Service} instance. |
|
45 | + * |
|
46 | + * @since 3.15.4 |
|
47 | + * |
|
48 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
49 | + */ |
|
50 | + private $log; |
|
51 | + |
|
52 | + /** |
|
53 | + * Create the {@link Wordlift_Admin_Post_Edit_Page} instance. |
|
54 | + * |
|
55 | + * @param \Wordlift $plugin The {@link Wordlift} plugin instance. |
|
56 | + * |
|
57 | + * @since 3.11.0 |
|
58 | + */ |
|
59 | + public function __construct( $plugin ) { |
|
60 | + |
|
61 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
62 | + |
|
63 | + add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_scripts_gutenberg' ) ); |
|
64 | + |
|
65 | + // Bail out if we're in the UX Builder editor. |
|
66 | + if ( $this->is_ux_builder_editor() ) { |
|
67 | + $this->log->info( 'WordLift will not show, since we are in UX Builder editor.' ); |
|
68 | + |
|
69 | + return; |
|
70 | + } |
|
71 | + |
|
72 | + // Define the callbacks. |
|
73 | + $callback = array( $this, 'enqueue_scripts' ); |
|
74 | + // Set a hook to enqueue scripts only when the edit page is displayed. |
|
75 | + add_action( 'admin_print_scripts-post.php', $callback ); |
|
76 | + add_action( 'admin_print_scripts-post-new.php', $callback ); |
|
77 | + |
|
78 | + $this->plugin = $plugin; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Check whether the current post opens with G'berg or not. |
|
83 | + * |
|
84 | + * @return bool True if G'berg is used otherwise false. |
|
85 | + * @since 3.22.3 |
|
86 | + */ |
|
87 | + public function is_gutenberg_page() { |
|
88 | + if ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) { |
|
89 | + // The Gutenberg plugin is on. |
|
90 | + return true; |
|
91 | + } |
|
92 | + |
|
93 | + $current_screen = get_current_screen(); |
|
94 | + if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) { |
|
95 | + // Gutenberg page on 5+. |
|
96 | + return true; |
|
97 | + } |
|
98 | + |
|
99 | + return false; |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Check if we're in UX builder. |
|
104 | + * |
|
105 | + * @see https://github.com/insideout10/wordlift-plugin/issues/691 |
|
106 | + * |
|
107 | + * @since 3.15.4 |
|
108 | + * |
|
109 | + * @return bool True if we're in UX builder, otherwise false. |
|
110 | + */ |
|
111 | + private function is_ux_builder_editor() { |
|
112 | + |
|
113 | + return function_exists( 'ux_builder_is_editor' ) |
|
114 | + && ux_builder_is_editor(); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Enqueue scripts and styles for the edit page. |
|
119 | + * |
|
120 | + * @since 3.11.0 |
|
121 | + */ |
|
122 | + public function enqueue_scripts() { |
|
123 | + |
|
124 | + // Dequeue potentially conflicting ontrapages angular scripts which any *are not* used on the edit screen. |
|
125 | + // |
|
126 | + // @see https://github.com/insideout10/wordlift-plugin/issues/832 |
|
127 | + wp_dequeue_script( 'ontrapagesAngular' ); |
|
128 | + wp_dequeue_script( 'ontrapagesApp' ); |
|
129 | + wp_dequeue_script( 'ontrapagesController' ); |
|
130 | + |
|
131 | + // Bail out if this is G'berg. |
|
132 | + if ( $this->is_gutenberg_page() ) { |
|
133 | + return; |
|
134 | + } |
|
135 | + |
|
136 | + // If Gutenberg is enabled for the post, do not load the legacy edit.js. |
|
137 | + if ( function_exists( 'use_block_editor_for_post' ) && use_block_editor_for_post( get_post() ) ) { |
|
138 | + return; |
|
139 | + } |
|
140 | + |
|
141 | + // Bail out if classification sidebar is not enabled via hook |
|
142 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
143 | + if ( ! apply_filters( 'wl_feature__enable__classification-sidebar', true ) ) { |
|
144 | + return; |
|
145 | + } |
|
146 | + |
|
147 | + /* |
|
148 | 148 | * Enqueue the edit screen JavaScript. The `wordlift-admin.bundle.js` file |
149 | 149 | * is scheduled to replace the older `wordlift-admin.min.js` once client-side |
150 | 150 | * code is properly refactored. |
@@ -153,178 +153,178 @@ discard block |
||
153 | 153 | * |
154 | 154 | * @since 3.20.0 edit.js has been migrated to the new webpack configuration. |
155 | 155 | */ |
156 | - $script_name = plugin_dir_url( __DIR__ ) . 'js/dist/edit'; |
|
157 | - |
|
158 | - /** |
|
159 | - * Scripts_Helper introduced. |
|
160 | - * |
|
161 | - * @since 3.25.0 Scripts are loaded using script helper to ensure WP 4.4 compatibiility. |
|
162 | - * @since 3.25.1 The handle is used to hook the wp_localize_script for the _wlEntityTypes global object. |
|
163 | - */ |
|
164 | - Scripts_Helper::enqueue_based_on_wordpress_version( |
|
165 | - 'wl-classic-editor', |
|
166 | - $script_name, |
|
167 | - array( |
|
168 | - $this->plugin->get_plugin_name(), |
|
169 | - 'jquery', |
|
170 | - // Require wp.ajax. |
|
171 | - 'wp-util', |
|
172 | - // @@todo: provide the following dependencies when we're in WP < 5.0 (i.e. when these dependencies aren't already defined). |
|
173 | - 'react', |
|
174 | - 'react-dom', |
|
175 | - 'wp-element', |
|
176 | - 'wp-polyfill', |
|
177 | - /* |
|
156 | + $script_name = plugin_dir_url( __DIR__ ) . 'js/dist/edit'; |
|
157 | + |
|
158 | + /** |
|
159 | + * Scripts_Helper introduced. |
|
160 | + * |
|
161 | + * @since 3.25.0 Scripts are loaded using script helper to ensure WP 4.4 compatibiility. |
|
162 | + * @since 3.25.1 The handle is used to hook the wp_localize_script for the _wlEntityTypes global object. |
|
163 | + */ |
|
164 | + Scripts_Helper::enqueue_based_on_wordpress_version( |
|
165 | + 'wl-classic-editor', |
|
166 | + $script_name, |
|
167 | + array( |
|
168 | + $this->plugin->get_plugin_name(), |
|
169 | + 'jquery', |
|
170 | + // Require wp.ajax. |
|
171 | + 'wp-util', |
|
172 | + // @@todo: provide the following dependencies when we're in WP < 5.0 (i.e. when these dependencies aren't already defined). |
|
173 | + 'react', |
|
174 | + 'react-dom', |
|
175 | + 'wp-element', |
|
176 | + 'wp-polyfill', |
|
177 | + /* |
|
178 | 178 | * Angular isn't loaded anymore remotely, but it is loaded within wordlift-reloaded.js. |
179 | 179 | * |
180 | 180 | * See https://github.com/insideout10/wordlift-plugin/issues/865. |
181 | 181 | * |
182 | 182 | * @since 3.19.6 |
183 | 183 | */ |
184 | - // Require Angular. |
|
185 | - // 'wl-angular', |
|
186 | - // 'wl-angular-geolocation', |
|
187 | - // 'wl-angular-touch', |
|
188 | - // 'wl-angular-animate', |
|
189 | - /** |
|
190 | - * We need the `wp.hooks` global to allow the edit.js script to send actions. |
|
191 | - * |
|
192 | - * @since 3.23.0 |
|
193 | - */ |
|
194 | - 'wp-hooks', |
|
195 | - ) |
|
196 | - ); |
|
197 | - |
|
198 | - wp_enqueue_style( 'wl-classic-editor', "$script_name.css", array(), $this->plugin->get_version() ); |
|
199 | - // Disable Faq Editor. |
|
200 | - // $this->load_faq_scripts_and_styles(); |
|
201 | - // $this->load_faq_settings( self::TINY_MCE ); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Enqueue the scripts and styles needed for FAQ |
|
206 | - */ |
|
207 | - private function load_faq_scripts_and_styles() { |
|
208 | - wp_enqueue_style( |
|
209 | - 'wl-faq-metabox-style', |
|
210 | - plugin_dir_url( __DIR__ ) . 'js/dist/faq.css', |
|
211 | - array(), |
|
212 | - WORDLIFT_VERSION |
|
213 | - ); |
|
214 | - Scripts_Helper::enqueue_based_on_wordpress_version( |
|
215 | - 'wl-faq-metabox-script', |
|
216 | - plugin_dir_url( __DIR__ ) . 'js/dist/faq', |
|
217 | - array( 'wp-polyfill' ), |
|
218 | - true |
|
219 | - ); |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Get FAQ settings array |
|
224 | - * |
|
225 | - * @return array |
|
226 | - */ |
|
227 | - public function get_faq_settings() { |
|
228 | - return array( |
|
229 | - 'restUrl' => get_rest_url( null, WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faq' ), |
|
230 | - 'listBoxId' => self::FAQ_LIST_BOX_ID, |
|
231 | - 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
232 | - 'postId' => get_the_ID(), |
|
233 | - // Translation for warning, error message. |
|
234 | - /* translators: %s: The invalid tag. */ |
|
235 | - 'invalidTagMessage' => sprintf( __( 'Invalid tags %s is present in answer', 'wordlift' ), '{INVALID_TAGS}' ), |
|
236 | - /* translators: %s: The word count limit warning. */ |
|
237 | - 'invalidWordCountMessage' => sprintf( __( 'Answer word count must not exceed %s words', 'wordlift' ), '{ANSWER_WORD_COUNT_WARNING_LIMIT}' ), |
|
238 | - 'questionText' => __( 'Question', 'wordlift' ), |
|
239 | - 'answerText' => __( 'Answer', 'wordlift' ), |
|
240 | - 'addQuestionOrAnswerText' => __( 'Add Question / Answer', 'wordlift' ), |
|
241 | - 'addQuestionText' => __( 'Add Question', 'wordlift' ), |
|
242 | - 'addAnswerText' => __( 'Add Answer', 'wordlift' ), |
|
243 | - 'noFaqItemsText' => __( 'Highlight a question in content, then click Add Question.', 'wordlift' ), |
|
244 | - 'updatingText' => __( 'Updating...', 'wordlift' ), |
|
245 | - ); |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Load FAQ settings to the add/edit post page |
|
250 | - * |
|
251 | - * @param $editor string specifying which text editor needed to be used. |
|
252 | - */ |
|
253 | - private function load_faq_settings( $editor ) { |
|
254 | - // This script also provides translations to gutenberg. |
|
255 | - wp_localize_script( 'wl-faq-metabox-script', '_wlFaqSettings', $this->get_faq_settings() ); |
|
256 | - |
|
257 | - // Enqueue the FAQ style |
|
258 | - if ( self::GUTENBERG === $editor ) { |
|
259 | - Scripts_Helper::enqueue_based_on_wordpress_version( |
|
260 | - 'wl-faq-gutenberg-plugin', |
|
261 | - plugin_dir_url( __DIR__ ) . 'js/dist/block-editor-faq-plugin', |
|
262 | - array( 'wp-polyfill' ), |
|
263 | - true |
|
264 | - ); |
|
265 | - } |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * Enqueue scripts and styles for the gutenberg edit page. |
|
270 | - * |
|
271 | - * @since 3.21.0 |
|
272 | - */ |
|
273 | - public function enqueue_scripts_gutenberg() { |
|
274 | - // Load FAQ settings. - Disabled for now |
|
275 | - // $this->load_faq_scripts_and_styles(); |
|
276 | - // $this->load_faq_settings( self::GUTENBERG ); |
|
277 | - |
|
278 | - wp_register_script( |
|
279 | - 'wl-block-editor', |
|
280 | - plugin_dir_url( __DIR__ ) . 'js/dist/block-editor.js', |
|
281 | - array( |
|
282 | - 'react', |
|
283 | - 'wordlift', |
|
284 | - 'wp-hooks', |
|
285 | - 'wp-data', |
|
286 | - 'wp-rich-text', |
|
287 | - 'wp-blocks', |
|
288 | - 'wp-plugins', |
|
289 | - 'wp-edit-post', |
|
290 | - ), |
|
291 | - $this->plugin->get_version(), |
|
292 | - false |
|
293 | - ); |
|
294 | - wp_localize_script( |
|
295 | - 'wl-block-editor', |
|
296 | - '_wlBlockEditorSettings', |
|
297 | - array( |
|
298 | - 'root' => esc_url_raw( rest_url() ), |
|
299 | - 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
300 | - ) |
|
301 | - ); |
|
302 | - |
|
303 | - /* |
|
184 | + // Require Angular. |
|
185 | + // 'wl-angular', |
|
186 | + // 'wl-angular-geolocation', |
|
187 | + // 'wl-angular-touch', |
|
188 | + // 'wl-angular-animate', |
|
189 | + /** |
|
190 | + * We need the `wp.hooks` global to allow the edit.js script to send actions. |
|
191 | + * |
|
192 | + * @since 3.23.0 |
|
193 | + */ |
|
194 | + 'wp-hooks', |
|
195 | + ) |
|
196 | + ); |
|
197 | + |
|
198 | + wp_enqueue_style( 'wl-classic-editor', "$script_name.css", array(), $this->plugin->get_version() ); |
|
199 | + // Disable Faq Editor. |
|
200 | + // $this->load_faq_scripts_and_styles(); |
|
201 | + // $this->load_faq_settings( self::TINY_MCE ); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Enqueue the scripts and styles needed for FAQ |
|
206 | + */ |
|
207 | + private function load_faq_scripts_and_styles() { |
|
208 | + wp_enqueue_style( |
|
209 | + 'wl-faq-metabox-style', |
|
210 | + plugin_dir_url( __DIR__ ) . 'js/dist/faq.css', |
|
211 | + array(), |
|
212 | + WORDLIFT_VERSION |
|
213 | + ); |
|
214 | + Scripts_Helper::enqueue_based_on_wordpress_version( |
|
215 | + 'wl-faq-metabox-script', |
|
216 | + plugin_dir_url( __DIR__ ) . 'js/dist/faq', |
|
217 | + array( 'wp-polyfill' ), |
|
218 | + true |
|
219 | + ); |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Get FAQ settings array |
|
224 | + * |
|
225 | + * @return array |
|
226 | + */ |
|
227 | + public function get_faq_settings() { |
|
228 | + return array( |
|
229 | + 'restUrl' => get_rest_url( null, WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faq' ), |
|
230 | + 'listBoxId' => self::FAQ_LIST_BOX_ID, |
|
231 | + 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
232 | + 'postId' => get_the_ID(), |
|
233 | + // Translation for warning, error message. |
|
234 | + /* translators: %s: The invalid tag. */ |
|
235 | + 'invalidTagMessage' => sprintf( __( 'Invalid tags %s is present in answer', 'wordlift' ), '{INVALID_TAGS}' ), |
|
236 | + /* translators: %s: The word count limit warning. */ |
|
237 | + 'invalidWordCountMessage' => sprintf( __( 'Answer word count must not exceed %s words', 'wordlift' ), '{ANSWER_WORD_COUNT_WARNING_LIMIT}' ), |
|
238 | + 'questionText' => __( 'Question', 'wordlift' ), |
|
239 | + 'answerText' => __( 'Answer', 'wordlift' ), |
|
240 | + 'addQuestionOrAnswerText' => __( 'Add Question / Answer', 'wordlift' ), |
|
241 | + 'addQuestionText' => __( 'Add Question', 'wordlift' ), |
|
242 | + 'addAnswerText' => __( 'Add Answer', 'wordlift' ), |
|
243 | + 'noFaqItemsText' => __( 'Highlight a question in content, then click Add Question.', 'wordlift' ), |
|
244 | + 'updatingText' => __( 'Updating...', 'wordlift' ), |
|
245 | + ); |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Load FAQ settings to the add/edit post page |
|
250 | + * |
|
251 | + * @param $editor string specifying which text editor needed to be used. |
|
252 | + */ |
|
253 | + private function load_faq_settings( $editor ) { |
|
254 | + // This script also provides translations to gutenberg. |
|
255 | + wp_localize_script( 'wl-faq-metabox-script', '_wlFaqSettings', $this->get_faq_settings() ); |
|
256 | + |
|
257 | + // Enqueue the FAQ style |
|
258 | + if ( self::GUTENBERG === $editor ) { |
|
259 | + Scripts_Helper::enqueue_based_on_wordpress_version( |
|
260 | + 'wl-faq-gutenberg-plugin', |
|
261 | + plugin_dir_url( __DIR__ ) . 'js/dist/block-editor-faq-plugin', |
|
262 | + array( 'wp-polyfill' ), |
|
263 | + true |
|
264 | + ); |
|
265 | + } |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * Enqueue scripts and styles for the gutenberg edit page. |
|
270 | + * |
|
271 | + * @since 3.21.0 |
|
272 | + */ |
|
273 | + public function enqueue_scripts_gutenberg() { |
|
274 | + // Load FAQ settings. - Disabled for now |
|
275 | + // $this->load_faq_scripts_and_styles(); |
|
276 | + // $this->load_faq_settings( self::GUTENBERG ); |
|
277 | + |
|
278 | + wp_register_script( |
|
279 | + 'wl-block-editor', |
|
280 | + plugin_dir_url( __DIR__ ) . 'js/dist/block-editor.js', |
|
281 | + array( |
|
282 | + 'react', |
|
283 | + 'wordlift', |
|
284 | + 'wp-hooks', |
|
285 | + 'wp-data', |
|
286 | + 'wp-rich-text', |
|
287 | + 'wp-blocks', |
|
288 | + 'wp-plugins', |
|
289 | + 'wp-edit-post', |
|
290 | + ), |
|
291 | + $this->plugin->get_version(), |
|
292 | + false |
|
293 | + ); |
|
294 | + wp_localize_script( |
|
295 | + 'wl-block-editor', |
|
296 | + '_wlBlockEditorSettings', |
|
297 | + array( |
|
298 | + 'root' => esc_url_raw( rest_url() ), |
|
299 | + 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
300 | + ) |
|
301 | + ); |
|
302 | + |
|
303 | + /* |
|
304 | 304 | * @since 3.25.1 The hook is used by the wp_localize_script to register the _wlEntityTypes global object. |
305 | 305 | */ |
306 | - wp_enqueue_style( |
|
307 | - 'wl-block-editor', |
|
308 | - plugin_dir_url( __DIR__ ) . 'js/dist/block-editor.css', |
|
309 | - array(), |
|
310 | - $this->plugin->get_version() |
|
311 | - ); |
|
312 | - |
|
313 | - wp_enqueue_script( |
|
314 | - 'wl-autocomplete-select', |
|
315 | - plugin_dir_url( __DIR__ ) . 'js/dist/autocomplete-select.js', |
|
316 | - array(), |
|
317 | - $this->plugin->get_version(), |
|
318 | - true |
|
319 | - ); |
|
320 | - |
|
321 | - wp_enqueue_style( |
|
322 | - 'wl-autocomplete-select', |
|
323 | - plugin_dir_url( __DIR__ ) . 'js/dist/autocomplete-select.css', |
|
324 | - array(), |
|
325 | - $this->plugin->get_version() |
|
326 | - ); |
|
327 | - |
|
328 | - } |
|
306 | + wp_enqueue_style( |
|
307 | + 'wl-block-editor', |
|
308 | + plugin_dir_url( __DIR__ ) . 'js/dist/block-editor.css', |
|
309 | + array(), |
|
310 | + $this->plugin->get_version() |
|
311 | + ); |
|
312 | + |
|
313 | + wp_enqueue_script( |
|
314 | + 'wl-autocomplete-select', |
|
315 | + plugin_dir_url( __DIR__ ) . 'js/dist/autocomplete-select.js', |
|
316 | + array(), |
|
317 | + $this->plugin->get_version(), |
|
318 | + true |
|
319 | + ); |
|
320 | + |
|
321 | + wp_enqueue_style( |
|
322 | + 'wl-autocomplete-select', |
|
323 | + plugin_dir_url( __DIR__ ) . 'js/dist/autocomplete-select.css', |
|
324 | + array(), |
|
325 | + $this->plugin->get_version() |
|
326 | + ); |
|
327 | + |
|
328 | + } |
|
329 | 329 | |
330 | 330 | } |
@@ -56,24 +56,24 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @since 3.11.0 |
58 | 58 | */ |
59 | - public function __construct( $plugin ) { |
|
59 | + public function __construct($plugin) { |
|
60 | 60 | |
61 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
61 | + $this->log = Wordlift_Log_Service::get_logger(get_class()); |
|
62 | 62 | |
63 | - add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_scripts_gutenberg' ) ); |
|
63 | + add_action('enqueue_block_editor_assets', array($this, 'enqueue_scripts_gutenberg')); |
|
64 | 64 | |
65 | 65 | // Bail out if we're in the UX Builder editor. |
66 | - if ( $this->is_ux_builder_editor() ) { |
|
67 | - $this->log->info( 'WordLift will not show, since we are in UX Builder editor.' ); |
|
66 | + if ($this->is_ux_builder_editor()) { |
|
67 | + $this->log->info('WordLift will not show, since we are in UX Builder editor.'); |
|
68 | 68 | |
69 | 69 | return; |
70 | 70 | } |
71 | 71 | |
72 | 72 | // Define the callbacks. |
73 | - $callback = array( $this, 'enqueue_scripts' ); |
|
73 | + $callback = array($this, 'enqueue_scripts'); |
|
74 | 74 | // Set a hook to enqueue scripts only when the edit page is displayed. |
75 | - add_action( 'admin_print_scripts-post.php', $callback ); |
|
76 | - add_action( 'admin_print_scripts-post-new.php', $callback ); |
|
75 | + add_action('admin_print_scripts-post.php', $callback); |
|
76 | + add_action('admin_print_scripts-post-new.php', $callback); |
|
77 | 77 | |
78 | 78 | $this->plugin = $plugin; |
79 | 79 | } |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | * @since 3.22.3 |
86 | 86 | */ |
87 | 87 | public function is_gutenberg_page() { |
88 | - if ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) { |
|
88 | + if (function_exists('is_gutenberg_page') && is_gutenberg_page()) { |
|
89 | 89 | // The Gutenberg plugin is on. |
90 | 90 | return true; |
91 | 91 | } |
92 | 92 | |
93 | 93 | $current_screen = get_current_screen(); |
94 | - if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) { |
|
94 | + if (method_exists($current_screen, 'is_block_editor') && $current_screen->is_block_editor()) { |
|
95 | 95 | // Gutenberg page on 5+. |
96 | 96 | return true; |
97 | 97 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | */ |
111 | 111 | private function is_ux_builder_editor() { |
112 | 112 | |
113 | - return function_exists( 'ux_builder_is_editor' ) |
|
113 | + return function_exists('ux_builder_is_editor') |
|
114 | 114 | && ux_builder_is_editor(); |
115 | 115 | } |
116 | 116 | |
@@ -124,23 +124,23 @@ discard block |
||
124 | 124 | // Dequeue potentially conflicting ontrapages angular scripts which any *are not* used on the edit screen. |
125 | 125 | // |
126 | 126 | // @see https://github.com/insideout10/wordlift-plugin/issues/832 |
127 | - wp_dequeue_script( 'ontrapagesAngular' ); |
|
128 | - wp_dequeue_script( 'ontrapagesApp' ); |
|
129 | - wp_dequeue_script( 'ontrapagesController' ); |
|
127 | + wp_dequeue_script('ontrapagesAngular'); |
|
128 | + wp_dequeue_script('ontrapagesApp'); |
|
129 | + wp_dequeue_script('ontrapagesController'); |
|
130 | 130 | |
131 | 131 | // Bail out if this is G'berg. |
132 | - if ( $this->is_gutenberg_page() ) { |
|
132 | + if ($this->is_gutenberg_page()) { |
|
133 | 133 | return; |
134 | 134 | } |
135 | 135 | |
136 | 136 | // If Gutenberg is enabled for the post, do not load the legacy edit.js. |
137 | - if ( function_exists( 'use_block_editor_for_post' ) && use_block_editor_for_post( get_post() ) ) { |
|
137 | + if (function_exists('use_block_editor_for_post') && use_block_editor_for_post(get_post())) { |
|
138 | 138 | return; |
139 | 139 | } |
140 | 140 | |
141 | 141 | // Bail out if classification sidebar is not enabled via hook |
142 | 142 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
143 | - if ( ! apply_filters( 'wl_feature__enable__classification-sidebar', true ) ) { |
|
143 | + if ( ! apply_filters('wl_feature__enable__classification-sidebar', true)) { |
|
144 | 144 | return; |
145 | 145 | } |
146 | 146 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * |
154 | 154 | * @since 3.20.0 edit.js has been migrated to the new webpack configuration. |
155 | 155 | */ |
156 | - $script_name = plugin_dir_url( __DIR__ ) . 'js/dist/edit'; |
|
156 | + $script_name = plugin_dir_url(__DIR__).'js/dist/edit'; |
|
157 | 157 | |
158 | 158 | /** |
159 | 159 | * Scripts_Helper introduced. |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | ) |
196 | 196 | ); |
197 | 197 | |
198 | - wp_enqueue_style( 'wl-classic-editor', "$script_name.css", array(), $this->plugin->get_version() ); |
|
198 | + wp_enqueue_style('wl-classic-editor', "$script_name.css", array(), $this->plugin->get_version()); |
|
199 | 199 | // Disable Faq Editor. |
200 | 200 | // $this->load_faq_scripts_and_styles(); |
201 | 201 | // $this->load_faq_settings( self::TINY_MCE ); |
@@ -207,14 +207,14 @@ discard block |
||
207 | 207 | private function load_faq_scripts_and_styles() { |
208 | 208 | wp_enqueue_style( |
209 | 209 | 'wl-faq-metabox-style', |
210 | - plugin_dir_url( __DIR__ ) . 'js/dist/faq.css', |
|
210 | + plugin_dir_url(__DIR__).'js/dist/faq.css', |
|
211 | 211 | array(), |
212 | 212 | WORDLIFT_VERSION |
213 | 213 | ); |
214 | 214 | Scripts_Helper::enqueue_based_on_wordpress_version( |
215 | 215 | 'wl-faq-metabox-script', |
216 | - plugin_dir_url( __DIR__ ) . 'js/dist/faq', |
|
217 | - array( 'wp-polyfill' ), |
|
216 | + plugin_dir_url(__DIR__).'js/dist/faq', |
|
217 | + array('wp-polyfill'), |
|
218 | 218 | true |
219 | 219 | ); |
220 | 220 | } |
@@ -226,22 +226,22 @@ discard block |
||
226 | 226 | */ |
227 | 227 | public function get_faq_settings() { |
228 | 228 | return array( |
229 | - 'restUrl' => get_rest_url( null, WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faq' ), |
|
229 | + 'restUrl' => get_rest_url(null, WL_REST_ROUTE_DEFAULT_NAMESPACE.'/faq'), |
|
230 | 230 | 'listBoxId' => self::FAQ_LIST_BOX_ID, |
231 | - 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
231 | + 'nonce' => wp_create_nonce('wp_rest'), |
|
232 | 232 | 'postId' => get_the_ID(), |
233 | 233 | // Translation for warning, error message. |
234 | 234 | /* translators: %s: The invalid tag. */ |
235 | - 'invalidTagMessage' => sprintf( __( 'Invalid tags %s is present in answer', 'wordlift' ), '{INVALID_TAGS}' ), |
|
235 | + 'invalidTagMessage' => sprintf(__('Invalid tags %s is present in answer', 'wordlift'), '{INVALID_TAGS}'), |
|
236 | 236 | /* translators: %s: The word count limit warning. */ |
237 | - 'invalidWordCountMessage' => sprintf( __( 'Answer word count must not exceed %s words', 'wordlift' ), '{ANSWER_WORD_COUNT_WARNING_LIMIT}' ), |
|
238 | - 'questionText' => __( 'Question', 'wordlift' ), |
|
239 | - 'answerText' => __( 'Answer', 'wordlift' ), |
|
240 | - 'addQuestionOrAnswerText' => __( 'Add Question / Answer', 'wordlift' ), |
|
241 | - 'addQuestionText' => __( 'Add Question', 'wordlift' ), |
|
242 | - 'addAnswerText' => __( 'Add Answer', 'wordlift' ), |
|
243 | - 'noFaqItemsText' => __( 'Highlight a question in content, then click Add Question.', 'wordlift' ), |
|
244 | - 'updatingText' => __( 'Updating...', 'wordlift' ), |
|
237 | + 'invalidWordCountMessage' => sprintf(__('Answer word count must not exceed %s words', 'wordlift'), '{ANSWER_WORD_COUNT_WARNING_LIMIT}'), |
|
238 | + 'questionText' => __('Question', 'wordlift'), |
|
239 | + 'answerText' => __('Answer', 'wordlift'), |
|
240 | + 'addQuestionOrAnswerText' => __('Add Question / Answer', 'wordlift'), |
|
241 | + 'addQuestionText' => __('Add Question', 'wordlift'), |
|
242 | + 'addAnswerText' => __('Add Answer', 'wordlift'), |
|
243 | + 'noFaqItemsText' => __('Highlight a question in content, then click Add Question.', 'wordlift'), |
|
244 | + 'updatingText' => __('Updating...', 'wordlift'), |
|
245 | 245 | ); |
246 | 246 | } |
247 | 247 | |
@@ -250,16 +250,16 @@ discard block |
||
250 | 250 | * |
251 | 251 | * @param $editor string specifying which text editor needed to be used. |
252 | 252 | */ |
253 | - private function load_faq_settings( $editor ) { |
|
253 | + private function load_faq_settings($editor) { |
|
254 | 254 | // This script also provides translations to gutenberg. |
255 | - wp_localize_script( 'wl-faq-metabox-script', '_wlFaqSettings', $this->get_faq_settings() ); |
|
255 | + wp_localize_script('wl-faq-metabox-script', '_wlFaqSettings', $this->get_faq_settings()); |
|
256 | 256 | |
257 | 257 | // Enqueue the FAQ style |
258 | - if ( self::GUTENBERG === $editor ) { |
|
258 | + if (self::GUTENBERG === $editor) { |
|
259 | 259 | Scripts_Helper::enqueue_based_on_wordpress_version( |
260 | 260 | 'wl-faq-gutenberg-plugin', |
261 | - plugin_dir_url( __DIR__ ) . 'js/dist/block-editor-faq-plugin', |
|
262 | - array( 'wp-polyfill' ), |
|
261 | + plugin_dir_url(__DIR__).'js/dist/block-editor-faq-plugin', |
|
262 | + array('wp-polyfill'), |
|
263 | 263 | true |
264 | 264 | ); |
265 | 265 | } |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | |
278 | 278 | wp_register_script( |
279 | 279 | 'wl-block-editor', |
280 | - plugin_dir_url( __DIR__ ) . 'js/dist/block-editor.js', |
|
280 | + plugin_dir_url(__DIR__).'js/dist/block-editor.js', |
|
281 | 281 | array( |
282 | 282 | 'react', |
283 | 283 | 'wordlift', |
@@ -295,8 +295,8 @@ discard block |
||
295 | 295 | 'wl-block-editor', |
296 | 296 | '_wlBlockEditorSettings', |
297 | 297 | array( |
298 | - 'root' => esc_url_raw( rest_url() ), |
|
299 | - 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
298 | + 'root' => esc_url_raw(rest_url()), |
|
299 | + 'nonce' => wp_create_nonce('wp_rest'), |
|
300 | 300 | ) |
301 | 301 | ); |
302 | 302 | |
@@ -305,14 +305,14 @@ discard block |
||
305 | 305 | */ |
306 | 306 | wp_enqueue_style( |
307 | 307 | 'wl-block-editor', |
308 | - plugin_dir_url( __DIR__ ) . 'js/dist/block-editor.css', |
|
308 | + plugin_dir_url(__DIR__).'js/dist/block-editor.css', |
|
309 | 309 | array(), |
310 | 310 | $this->plugin->get_version() |
311 | 311 | ); |
312 | 312 | |
313 | 313 | wp_enqueue_script( |
314 | 314 | 'wl-autocomplete-select', |
315 | - plugin_dir_url( __DIR__ ) . 'js/dist/autocomplete-select.js', |
|
315 | + plugin_dir_url(__DIR__).'js/dist/autocomplete-select.js', |
|
316 | 316 | array(), |
317 | 317 | $this->plugin->get_version(), |
318 | 318 | true |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | |
321 | 321 | wp_enqueue_style( |
322 | 322 | 'wl-autocomplete-select', |
323 | - plugin_dir_url( __DIR__ ) . 'js/dist/autocomplete-select.css', |
|
323 | + plugin_dir_url(__DIR__).'js/dist/autocomplete-select.css', |
|
324 | 324 | array(), |
325 | 325 | $this->plugin->get_version() |
326 | 326 | ); |
@@ -18,308 +18,308 @@ |
||
18 | 18 | */ |
19 | 19 | class Wordlift_Admin_Settings_Analytics_Page extends Wordlift_Admin_Page { |
20 | 20 | |
21 | - /** |
|
22 | - * A singleton instance of the Notice service. |
|
23 | - * |
|
24 | - * @since 3.21.0 |
|
25 | - * @access private |
|
26 | - * @var \Wordlift_Admin_Settings_Analytics_Page $instance A singleton instance of a {@link Wordlift_Admin_Settings_Analytics_Page} class. |
|
27 | - */ |
|
28 | - private static $instance; |
|
29 | - |
|
30 | - /** |
|
31 | - * A {@link Wordlift_Admin_Input_Element} element renderer. |
|
32 | - * |
|
33 | - * @since 3.21.0 |
|
34 | - * @access private |
|
35 | - * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer. |
|
36 | - */ |
|
37 | - private $input_element; |
|
38 | - |
|
39 | - /** |
|
40 | - * A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
41 | - * |
|
42 | - * @since 3.21.0 |
|
43 | - * @access protected |
|
44 | - * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
45 | - */ |
|
46 | - private $radio_input_element; |
|
47 | - |
|
48 | - /** |
|
49 | - * Create a {@link Wordlift_Admin_Settings_Page} instance. |
|
50 | - * |
|
51 | - * @param \Wordlift_Admin_Input_Element $input_element An input element class to output input boxes in a settings form. |
|
52 | - * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element A radio element input class for use in a settings form. |
|
53 | - * |
|
54 | - * @since 3.21.0 |
|
55 | - */ |
|
56 | - public function __construct( $input_element, $radio_input_element ) { |
|
57 | - |
|
58 | - // Set a reference to the UI elements. |
|
59 | - $this->input_element = $input_element; |
|
60 | - $this->radio_input_element = $radio_input_element; |
|
61 | - |
|
62 | - // Adds this page to the main admin settings tabbed menu. |
|
63 | - add_filter( 'wl_admin_page_tabs', array( $this, 'add_admin_page_tab' ) ); |
|
64 | - |
|
65 | - self::$instance = $this; |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Get the singleton instance of the Notice service. |
|
70 | - * |
|
71 | - * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service. |
|
72 | - * @since 3.21.0 |
|
73 | - */ |
|
74 | - public static function get_instance() { |
|
75 | - |
|
76 | - return self::$instance; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @inheritdoc |
|
81 | - */ |
|
82 | - protected function get_parent_slug() { |
|
83 | - |
|
84 | - return 'wl_admin_menu'; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @inheritdoc |
|
89 | - */ |
|
90 | - protected function get_capability() { |
|
91 | - |
|
92 | - return 'manage_options'; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * @inheritdoc |
|
97 | - */ |
|
98 | - public function get_page_title() { |
|
99 | - |
|
100 | - return __( 'WorldLift Analytics Settings', 'wordlift' ); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @inheritdoc |
|
105 | - */ |
|
106 | - public function get_menu_title() { |
|
107 | - |
|
108 | - return __( 'Analytics Settings', 'wordlift' ); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * @inheritdoc |
|
113 | - */ |
|
114 | - public function get_menu_slug() { |
|
115 | - |
|
116 | - return 'wl_configuration_admin_analytics_menu'; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @inheritdoc |
|
121 | - */ |
|
122 | - public function get_partial_name() { |
|
123 | - |
|
124 | - return 'wordlift-admin-settings-analytics-page.php'; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Returns the string to use for the tab slug on main admin settings page. |
|
129 | - * |
|
130 | - * @method get_admin_page_tab_slug |
|
131 | - * @return string |
|
132 | - * @since 3.21.0 |
|
133 | - */ |
|
134 | - public function get_admin_page_tab_slug() { |
|
135 | - return 'analytics'; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Adds pages to the tabs menu on the main admin settings page. |
|
140 | - * |
|
141 | - * @method add_admin_page_tab |
|
142 | - * @param array $tabs an array of tab titles and slugs to use when building a tabbed menu on option pages. |
|
143 | - * |
|
144 | - * @since 3.21.0 |
|
145 | - */ |
|
146 | - public function add_admin_page_tab( $tabs ) { |
|
147 | - if ( apply_filters( 'wl_feature__enable__analytics', true ) ) { |
|
148 | - $tabs[] = array( |
|
149 | - 'title' => $this->get_menu_title(), |
|
150 | - 'slug' => $this->get_admin_page_tab_slug(), |
|
151 | - ); |
|
152 | - } |
|
153 | - |
|
154 | - return $tabs; |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Configure all the configuration parameters. |
|
159 | - * |
|
160 | - * Called by the *admin_init* hook. |
|
161 | - * |
|
162 | - * @since 3.21.0 |
|
163 | - */ |
|
164 | - public function admin_init() { |
|
165 | - |
|
166 | - // Register WordLift's analytics settings with our in class sanitizer. |
|
167 | - register_setting( |
|
168 | - 'wl_analytics_settings', |
|
169 | - 'wl_analytics_settings', |
|
170 | - array( $this, 'sanitize_callback' ) |
|
171 | - ); |
|
172 | - |
|
173 | - // Add the analytics settings setction. |
|
174 | - add_settings_section( |
|
175 | - 'wl_analytics_settings_section', |
|
176 | - '', |
|
177 | - '', |
|
178 | - 'wl_analytics_settings' |
|
179 | - ); |
|
180 | - |
|
181 | - // Add a toggle to determine if analytics functions are enabled or not. |
|
182 | - // NOTE: this uses yes/no rather than true/false. |
|
183 | - add_settings_field( |
|
184 | - 'wl-analytics-enabled', |
|
185 | - __( 'Enable Analytics', 'wordlift' ), |
|
186 | - array( $this->radio_input_element, 'render' ), |
|
187 | - 'wl_analytics_settings', |
|
188 | - 'wl_analytics_settings_section', |
|
189 | - array( |
|
190 | - 'id' => 'wl-analytics-enable', |
|
191 | - 'name' => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENABLE . ']', |
|
192 | - 'value' => Wordlift_Configuration_Service::get_instance()->is_analytics_enable() ? 'yes' : 'no', |
|
193 | - 'description' => __( 'Toggle on/off the default values.', 'wordlift' ), |
|
194 | - ) |
|
195 | - ); |
|
196 | - |
|
197 | - /** |
|
198 | - * A basic number field that will accept anything from 1 to 20. |
|
199 | - * |
|
200 | - * Represents the custom dim number for the uri. |
|
201 | - */ |
|
202 | - add_settings_field( |
|
203 | - 'wl-analytics-entity-uri-dimension', |
|
204 | - __( 'Entity URI dimension', 'wordlift' ), |
|
205 | - array( $this->input_element, 'render' ), |
|
206 | - 'wl_analytics_settings', |
|
207 | - 'wl_analytics_settings_section', |
|
208 | - array( |
|
209 | - 'id' => 'wl-analytics-entity-uri-dimension', |
|
210 | - 'name' => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENTITY_URI_DIMENSION . ']', |
|
211 | - 'type' => 'number', |
|
212 | - 'value' => Wordlift_Configuration_Service::get_instance()->get_analytics_entity_uri_dimension(), |
|
213 | - 'description' => __( 'Entity URI dimesion', 'wordlift' ), |
|
214 | - ) |
|
215 | - ); |
|
216 | - |
|
217 | - /** |
|
218 | - * A basic number field that will accept anything from 1 to 20. |
|
219 | - * |
|
220 | - * Represents the custom dim number for the type. |
|
221 | - */ |
|
222 | - add_settings_field( |
|
223 | - 'wl-analytics-entity-type-dimension', |
|
224 | - __( 'Entity Type dimension', 'wordlift' ), |
|
225 | - array( $this->input_element, 'render' ), |
|
226 | - 'wl_analytics_settings', |
|
227 | - 'wl_analytics_settings_section', |
|
228 | - array( |
|
229 | - 'id' => 'wl-analytics-entity-type-dimension', |
|
230 | - 'name' => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENTITY_TYPE_DIMENSION . ']', |
|
231 | - 'type' => 'number', |
|
232 | - 'value' => Wordlift_Configuration_Service::get_instance()->get_analytics_entity_type_dimension(), |
|
233 | - 'description' => __( 'Entity Type dimension', 'wordlift' ), |
|
234 | - ) |
|
235 | - ); |
|
236 | - |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Validates an entity uri based on an integer passed. |
|
241 | - * |
|
242 | - * TODO: Needs a feedback method to pass back error messages. |
|
243 | - * |
|
244 | - * @method validate_entity_uri |
|
245 | - * @param string $uri a sting representing an entity ID that can be converted to a uri. |
|
246 | - * |
|
247 | - * @return int |
|
248 | - * @since 3.21.0 |
|
249 | - */ |
|
250 | - public function validate_entity_uri( $uri ) { |
|
251 | - // Basic validation is to ensure number is between 1 and 20. |
|
252 | - // NOTE: certain analytics accounts have a much higher value - as many |
|
253 | - // as 200 are allowed. |
|
254 | - if ( (int) $uri < 1 || (int) $uri > 20 ) { |
|
255 | - // if we are out of range then pass the default value. |
|
256 | - $uri = Wordlift_Configuration_Service::get_instance()->get_analytics_entity_uri_dimension(); |
|
257 | - } |
|
258 | - |
|
259 | - return absint( $uri ); |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Validates an entity type. |
|
264 | - * |
|
265 | - * TODO: Needs a feedback method to pass back error messages. |
|
266 | - * |
|
267 | - * @method validate_entity_type |
|
268 | - * @param string $type This is an entity type ID in string form - really a number. |
|
269 | - * |
|
270 | - * @return int |
|
271 | - * @since 3.21.0 |
|
272 | - */ |
|
273 | - public function validate_entity_type( $type ) { |
|
274 | - // Basic validation is to ensure number is between 1 and 20. |
|
275 | - // NOTE: certain analytics accounts have a much higher value - as many |
|
276 | - // as 200 are allowed. |
|
277 | - if ( (int) $type < 1 || (int) $type > 20 ) { |
|
278 | - // if we are out of range then pass the default value. |
|
279 | - $type = Wordlift_Configuration_Service::get_instance()->get_analytics_entity_type_dimension(); |
|
280 | - } |
|
281 | - |
|
282 | - return absint( $type ); |
|
283 | - } |
|
284 | - |
|
285 | - /** |
|
286 | - * Sanitize the configuration settings to be stored. |
|
287 | - * |
|
288 | - * If a new entity is being created for the publisher, create it and set The |
|
289 | - * publisher setting. |
|
290 | - * |
|
291 | - * @param array $input The configuration settings array. |
|
292 | - * |
|
293 | - * @return array The sanitized input array. |
|
294 | - * @since 3.21.0 |
|
295 | - */ |
|
296 | - public function sanitize_callback( $input ) { |
|
297 | - if ( ! check_admin_referer( 'wl_analytics_settings-options' ) ) { |
|
298 | - // Any failing nonce checks already die(). |
|
299 | - return; |
|
300 | - } |
|
301 | - |
|
302 | - /** |
|
303 | - * Validate and sanitize the $inputs and store them in $output saved. |
|
304 | - */ |
|
305 | - $output = array(); |
|
306 | - if ( isset( $input['analytics_enable'] ) ) { |
|
307 | - $output['analytics_enable'] = ( 'yes' === $input['analytics_enable'] ) ? 'yes' : 'no'; |
|
308 | - } |
|
309 | - if ( isset( $input['analytics_entity_uri_dimension'] ) ) { |
|
310 | - $output['analytics_entity_uri_dimension'] = (int) $this->validate_entity_uri( $input['analytics_entity_uri_dimension'] ); |
|
311 | - } |
|
312 | - if ( isset( $input['analytics_entity_type_dimension'] ) ) { |
|
313 | - // This dimension cannot be the same as the one set above. If it is |
|
314 | - // then zero it out and it will fail validation. |
|
315 | - if ( isset( $output['analytics_entity_uri_dimension'] ) && $output['analytics_entity_uri_dimension'] === (int) $input['analytics_entity_type_dimension'] ) { |
|
316 | - $input['analytics_entity_type_dimension'] = 0; |
|
317 | - } |
|
318 | - $output['analytics_entity_type_dimension'] = (int) $this->validate_entity_type( $input['analytics_entity_type_dimension'] ); |
|
319 | - } |
|
320 | - |
|
321 | - // return items added to the output for saving. |
|
322 | - return $output; |
|
323 | - } |
|
21 | + /** |
|
22 | + * A singleton instance of the Notice service. |
|
23 | + * |
|
24 | + * @since 3.21.0 |
|
25 | + * @access private |
|
26 | + * @var \Wordlift_Admin_Settings_Analytics_Page $instance A singleton instance of a {@link Wordlift_Admin_Settings_Analytics_Page} class. |
|
27 | + */ |
|
28 | + private static $instance; |
|
29 | + |
|
30 | + /** |
|
31 | + * A {@link Wordlift_Admin_Input_Element} element renderer. |
|
32 | + * |
|
33 | + * @since 3.21.0 |
|
34 | + * @access private |
|
35 | + * @var \Wordlift_Admin_Input_Element $input_element An {@link Wordlift_Admin_Input_Element} element renderer. |
|
36 | + */ |
|
37 | + private $input_element; |
|
38 | + |
|
39 | + /** |
|
40 | + * A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
41 | + * |
|
42 | + * @since 3.21.0 |
|
43 | + * @access protected |
|
44 | + * @var \Wordlift_Admin_Radio_Input_Element $radio_input_element A {@link Wordlift_Admin_Radio_Input_Element} element renderer. |
|
45 | + */ |
|
46 | + private $radio_input_element; |
|
47 | + |
|
48 | + /** |
|
49 | + * Create a {@link Wordlift_Admin_Settings_Page} instance. |
|
50 | + * |
|
51 | + * @param \Wordlift_Admin_Input_Element $input_element An input element class to output input boxes in a settings form. |
|
52 | + * @param \Wordlift_Admin_Radio_Input_Element $radio_input_element A radio element input class for use in a settings form. |
|
53 | + * |
|
54 | + * @since 3.21.0 |
|
55 | + */ |
|
56 | + public function __construct( $input_element, $radio_input_element ) { |
|
57 | + |
|
58 | + // Set a reference to the UI elements. |
|
59 | + $this->input_element = $input_element; |
|
60 | + $this->radio_input_element = $radio_input_element; |
|
61 | + |
|
62 | + // Adds this page to the main admin settings tabbed menu. |
|
63 | + add_filter( 'wl_admin_page_tabs', array( $this, 'add_admin_page_tab' ) ); |
|
64 | + |
|
65 | + self::$instance = $this; |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Get the singleton instance of the Notice service. |
|
70 | + * |
|
71 | + * @return \Wordlift_Admin_Settings_Page The singleton instance of the settings page service. |
|
72 | + * @since 3.21.0 |
|
73 | + */ |
|
74 | + public static function get_instance() { |
|
75 | + |
|
76 | + return self::$instance; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @inheritdoc |
|
81 | + */ |
|
82 | + protected function get_parent_slug() { |
|
83 | + |
|
84 | + return 'wl_admin_menu'; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @inheritdoc |
|
89 | + */ |
|
90 | + protected function get_capability() { |
|
91 | + |
|
92 | + return 'manage_options'; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * @inheritdoc |
|
97 | + */ |
|
98 | + public function get_page_title() { |
|
99 | + |
|
100 | + return __( 'WorldLift Analytics Settings', 'wordlift' ); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @inheritdoc |
|
105 | + */ |
|
106 | + public function get_menu_title() { |
|
107 | + |
|
108 | + return __( 'Analytics Settings', 'wordlift' ); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * @inheritdoc |
|
113 | + */ |
|
114 | + public function get_menu_slug() { |
|
115 | + |
|
116 | + return 'wl_configuration_admin_analytics_menu'; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @inheritdoc |
|
121 | + */ |
|
122 | + public function get_partial_name() { |
|
123 | + |
|
124 | + return 'wordlift-admin-settings-analytics-page.php'; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Returns the string to use for the tab slug on main admin settings page. |
|
129 | + * |
|
130 | + * @method get_admin_page_tab_slug |
|
131 | + * @return string |
|
132 | + * @since 3.21.0 |
|
133 | + */ |
|
134 | + public function get_admin_page_tab_slug() { |
|
135 | + return 'analytics'; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Adds pages to the tabs menu on the main admin settings page. |
|
140 | + * |
|
141 | + * @method add_admin_page_tab |
|
142 | + * @param array $tabs an array of tab titles and slugs to use when building a tabbed menu on option pages. |
|
143 | + * |
|
144 | + * @since 3.21.0 |
|
145 | + */ |
|
146 | + public function add_admin_page_tab( $tabs ) { |
|
147 | + if ( apply_filters( 'wl_feature__enable__analytics', true ) ) { |
|
148 | + $tabs[] = array( |
|
149 | + 'title' => $this->get_menu_title(), |
|
150 | + 'slug' => $this->get_admin_page_tab_slug(), |
|
151 | + ); |
|
152 | + } |
|
153 | + |
|
154 | + return $tabs; |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Configure all the configuration parameters. |
|
159 | + * |
|
160 | + * Called by the *admin_init* hook. |
|
161 | + * |
|
162 | + * @since 3.21.0 |
|
163 | + */ |
|
164 | + public function admin_init() { |
|
165 | + |
|
166 | + // Register WordLift's analytics settings with our in class sanitizer. |
|
167 | + register_setting( |
|
168 | + 'wl_analytics_settings', |
|
169 | + 'wl_analytics_settings', |
|
170 | + array( $this, 'sanitize_callback' ) |
|
171 | + ); |
|
172 | + |
|
173 | + // Add the analytics settings setction. |
|
174 | + add_settings_section( |
|
175 | + 'wl_analytics_settings_section', |
|
176 | + '', |
|
177 | + '', |
|
178 | + 'wl_analytics_settings' |
|
179 | + ); |
|
180 | + |
|
181 | + // Add a toggle to determine if analytics functions are enabled or not. |
|
182 | + // NOTE: this uses yes/no rather than true/false. |
|
183 | + add_settings_field( |
|
184 | + 'wl-analytics-enabled', |
|
185 | + __( 'Enable Analytics', 'wordlift' ), |
|
186 | + array( $this->radio_input_element, 'render' ), |
|
187 | + 'wl_analytics_settings', |
|
188 | + 'wl_analytics_settings_section', |
|
189 | + array( |
|
190 | + 'id' => 'wl-analytics-enable', |
|
191 | + 'name' => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENABLE . ']', |
|
192 | + 'value' => Wordlift_Configuration_Service::get_instance()->is_analytics_enable() ? 'yes' : 'no', |
|
193 | + 'description' => __( 'Toggle on/off the default values.', 'wordlift' ), |
|
194 | + ) |
|
195 | + ); |
|
196 | + |
|
197 | + /** |
|
198 | + * A basic number field that will accept anything from 1 to 20. |
|
199 | + * |
|
200 | + * Represents the custom dim number for the uri. |
|
201 | + */ |
|
202 | + add_settings_field( |
|
203 | + 'wl-analytics-entity-uri-dimension', |
|
204 | + __( 'Entity URI dimension', 'wordlift' ), |
|
205 | + array( $this->input_element, 'render' ), |
|
206 | + 'wl_analytics_settings', |
|
207 | + 'wl_analytics_settings_section', |
|
208 | + array( |
|
209 | + 'id' => 'wl-analytics-entity-uri-dimension', |
|
210 | + 'name' => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENTITY_URI_DIMENSION . ']', |
|
211 | + 'type' => 'number', |
|
212 | + 'value' => Wordlift_Configuration_Service::get_instance()->get_analytics_entity_uri_dimension(), |
|
213 | + 'description' => __( 'Entity URI dimesion', 'wordlift' ), |
|
214 | + ) |
|
215 | + ); |
|
216 | + |
|
217 | + /** |
|
218 | + * A basic number field that will accept anything from 1 to 20. |
|
219 | + * |
|
220 | + * Represents the custom dim number for the type. |
|
221 | + */ |
|
222 | + add_settings_field( |
|
223 | + 'wl-analytics-entity-type-dimension', |
|
224 | + __( 'Entity Type dimension', 'wordlift' ), |
|
225 | + array( $this->input_element, 'render' ), |
|
226 | + 'wl_analytics_settings', |
|
227 | + 'wl_analytics_settings_section', |
|
228 | + array( |
|
229 | + 'id' => 'wl-analytics-entity-type-dimension', |
|
230 | + 'name' => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENTITY_TYPE_DIMENSION . ']', |
|
231 | + 'type' => 'number', |
|
232 | + 'value' => Wordlift_Configuration_Service::get_instance()->get_analytics_entity_type_dimension(), |
|
233 | + 'description' => __( 'Entity Type dimension', 'wordlift' ), |
|
234 | + ) |
|
235 | + ); |
|
236 | + |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Validates an entity uri based on an integer passed. |
|
241 | + * |
|
242 | + * TODO: Needs a feedback method to pass back error messages. |
|
243 | + * |
|
244 | + * @method validate_entity_uri |
|
245 | + * @param string $uri a sting representing an entity ID that can be converted to a uri. |
|
246 | + * |
|
247 | + * @return int |
|
248 | + * @since 3.21.0 |
|
249 | + */ |
|
250 | + public function validate_entity_uri( $uri ) { |
|
251 | + // Basic validation is to ensure number is between 1 and 20. |
|
252 | + // NOTE: certain analytics accounts have a much higher value - as many |
|
253 | + // as 200 are allowed. |
|
254 | + if ( (int) $uri < 1 || (int) $uri > 20 ) { |
|
255 | + // if we are out of range then pass the default value. |
|
256 | + $uri = Wordlift_Configuration_Service::get_instance()->get_analytics_entity_uri_dimension(); |
|
257 | + } |
|
258 | + |
|
259 | + return absint( $uri ); |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Validates an entity type. |
|
264 | + * |
|
265 | + * TODO: Needs a feedback method to pass back error messages. |
|
266 | + * |
|
267 | + * @method validate_entity_type |
|
268 | + * @param string $type This is an entity type ID in string form - really a number. |
|
269 | + * |
|
270 | + * @return int |
|
271 | + * @since 3.21.0 |
|
272 | + */ |
|
273 | + public function validate_entity_type( $type ) { |
|
274 | + // Basic validation is to ensure number is between 1 and 20. |
|
275 | + // NOTE: certain analytics accounts have a much higher value - as many |
|
276 | + // as 200 are allowed. |
|
277 | + if ( (int) $type < 1 || (int) $type > 20 ) { |
|
278 | + // if we are out of range then pass the default value. |
|
279 | + $type = Wordlift_Configuration_Service::get_instance()->get_analytics_entity_type_dimension(); |
|
280 | + } |
|
281 | + |
|
282 | + return absint( $type ); |
|
283 | + } |
|
284 | + |
|
285 | + /** |
|
286 | + * Sanitize the configuration settings to be stored. |
|
287 | + * |
|
288 | + * If a new entity is being created for the publisher, create it and set The |
|
289 | + * publisher setting. |
|
290 | + * |
|
291 | + * @param array $input The configuration settings array. |
|
292 | + * |
|
293 | + * @return array The sanitized input array. |
|
294 | + * @since 3.21.0 |
|
295 | + */ |
|
296 | + public function sanitize_callback( $input ) { |
|
297 | + if ( ! check_admin_referer( 'wl_analytics_settings-options' ) ) { |
|
298 | + // Any failing nonce checks already die(). |
|
299 | + return; |
|
300 | + } |
|
301 | + |
|
302 | + /** |
|
303 | + * Validate and sanitize the $inputs and store them in $output saved. |
|
304 | + */ |
|
305 | + $output = array(); |
|
306 | + if ( isset( $input['analytics_enable'] ) ) { |
|
307 | + $output['analytics_enable'] = ( 'yes' === $input['analytics_enable'] ) ? 'yes' : 'no'; |
|
308 | + } |
|
309 | + if ( isset( $input['analytics_entity_uri_dimension'] ) ) { |
|
310 | + $output['analytics_entity_uri_dimension'] = (int) $this->validate_entity_uri( $input['analytics_entity_uri_dimension'] ); |
|
311 | + } |
|
312 | + if ( isset( $input['analytics_entity_type_dimension'] ) ) { |
|
313 | + // This dimension cannot be the same as the one set above. If it is |
|
314 | + // then zero it out and it will fail validation. |
|
315 | + if ( isset( $output['analytics_entity_uri_dimension'] ) && $output['analytics_entity_uri_dimension'] === (int) $input['analytics_entity_type_dimension'] ) { |
|
316 | + $input['analytics_entity_type_dimension'] = 0; |
|
317 | + } |
|
318 | + $output['analytics_entity_type_dimension'] = (int) $this->validate_entity_type( $input['analytics_entity_type_dimension'] ); |
|
319 | + } |
|
320 | + |
|
321 | + // return items added to the output for saving. |
|
322 | + return $output; |
|
323 | + } |
|
324 | 324 | |
325 | 325 | } |
@@ -53,14 +53,14 @@ discard block |
||
53 | 53 | * |
54 | 54 | * @since 3.21.0 |
55 | 55 | */ |
56 | - public function __construct( $input_element, $radio_input_element ) { |
|
56 | + public function __construct($input_element, $radio_input_element) { |
|
57 | 57 | |
58 | 58 | // Set a reference to the UI elements. |
59 | 59 | $this->input_element = $input_element; |
60 | 60 | $this->radio_input_element = $radio_input_element; |
61 | 61 | |
62 | 62 | // Adds this page to the main admin settings tabbed menu. |
63 | - add_filter( 'wl_admin_page_tabs', array( $this, 'add_admin_page_tab' ) ); |
|
63 | + add_filter('wl_admin_page_tabs', array($this, 'add_admin_page_tab')); |
|
64 | 64 | |
65 | 65 | self::$instance = $this; |
66 | 66 | } |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | */ |
98 | 98 | public function get_page_title() { |
99 | 99 | |
100 | - return __( 'WorldLift Analytics Settings', 'wordlift' ); |
|
100 | + return __('WorldLift Analytics Settings', 'wordlift'); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function get_menu_title() { |
107 | 107 | |
108 | - return __( 'Analytics Settings', 'wordlift' ); |
|
108 | + return __('Analytics Settings', 'wordlift'); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | /** |
@@ -143,8 +143,8 @@ discard block |
||
143 | 143 | * |
144 | 144 | * @since 3.21.0 |
145 | 145 | */ |
146 | - public function add_admin_page_tab( $tabs ) { |
|
147 | - if ( apply_filters( 'wl_feature__enable__analytics', true ) ) { |
|
146 | + public function add_admin_page_tab($tabs) { |
|
147 | + if (apply_filters('wl_feature__enable__analytics', true)) { |
|
148 | 148 | $tabs[] = array( |
149 | 149 | 'title' => $this->get_menu_title(), |
150 | 150 | 'slug' => $this->get_admin_page_tab_slug(), |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | register_setting( |
168 | 168 | 'wl_analytics_settings', |
169 | 169 | 'wl_analytics_settings', |
170 | - array( $this, 'sanitize_callback' ) |
|
170 | + array($this, 'sanitize_callback') |
|
171 | 171 | ); |
172 | 172 | |
173 | 173 | // Add the analytics settings setction. |
@@ -182,15 +182,15 @@ discard block |
||
182 | 182 | // NOTE: this uses yes/no rather than true/false. |
183 | 183 | add_settings_field( |
184 | 184 | 'wl-analytics-enabled', |
185 | - __( 'Enable Analytics', 'wordlift' ), |
|
186 | - array( $this->radio_input_element, 'render' ), |
|
185 | + __('Enable Analytics', 'wordlift'), |
|
186 | + array($this->radio_input_element, 'render'), |
|
187 | 187 | 'wl_analytics_settings', |
188 | 188 | 'wl_analytics_settings_section', |
189 | 189 | array( |
190 | 190 | 'id' => 'wl-analytics-enable', |
191 | - 'name' => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENABLE . ']', |
|
191 | + 'name' => 'wl_analytics_settings['.Wordlift_Configuration_Service::ANALYTICS_ENABLE.']', |
|
192 | 192 | 'value' => Wordlift_Configuration_Service::get_instance()->is_analytics_enable() ? 'yes' : 'no', |
193 | - 'description' => __( 'Toggle on/off the default values.', 'wordlift' ), |
|
193 | + 'description' => __('Toggle on/off the default values.', 'wordlift'), |
|
194 | 194 | ) |
195 | 195 | ); |
196 | 196 | |
@@ -201,16 +201,16 @@ discard block |
||
201 | 201 | */ |
202 | 202 | add_settings_field( |
203 | 203 | 'wl-analytics-entity-uri-dimension', |
204 | - __( 'Entity URI dimension', 'wordlift' ), |
|
205 | - array( $this->input_element, 'render' ), |
|
204 | + __('Entity URI dimension', 'wordlift'), |
|
205 | + array($this->input_element, 'render'), |
|
206 | 206 | 'wl_analytics_settings', |
207 | 207 | 'wl_analytics_settings_section', |
208 | 208 | array( |
209 | 209 | 'id' => 'wl-analytics-entity-uri-dimension', |
210 | - 'name' => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENTITY_URI_DIMENSION . ']', |
|
210 | + 'name' => 'wl_analytics_settings['.Wordlift_Configuration_Service::ANALYTICS_ENTITY_URI_DIMENSION.']', |
|
211 | 211 | 'type' => 'number', |
212 | 212 | 'value' => Wordlift_Configuration_Service::get_instance()->get_analytics_entity_uri_dimension(), |
213 | - 'description' => __( 'Entity URI dimesion', 'wordlift' ), |
|
213 | + 'description' => __('Entity URI dimesion', 'wordlift'), |
|
214 | 214 | ) |
215 | 215 | ); |
216 | 216 | |
@@ -221,16 +221,16 @@ discard block |
||
221 | 221 | */ |
222 | 222 | add_settings_field( |
223 | 223 | 'wl-analytics-entity-type-dimension', |
224 | - __( 'Entity Type dimension', 'wordlift' ), |
|
225 | - array( $this->input_element, 'render' ), |
|
224 | + __('Entity Type dimension', 'wordlift'), |
|
225 | + array($this->input_element, 'render'), |
|
226 | 226 | 'wl_analytics_settings', |
227 | 227 | 'wl_analytics_settings_section', |
228 | 228 | array( |
229 | 229 | 'id' => 'wl-analytics-entity-type-dimension', |
230 | - 'name' => 'wl_analytics_settings[' . Wordlift_Configuration_Service::ANALYTICS_ENTITY_TYPE_DIMENSION . ']', |
|
230 | + 'name' => 'wl_analytics_settings['.Wordlift_Configuration_Service::ANALYTICS_ENTITY_TYPE_DIMENSION.']', |
|
231 | 231 | 'type' => 'number', |
232 | 232 | 'value' => Wordlift_Configuration_Service::get_instance()->get_analytics_entity_type_dimension(), |
233 | - 'description' => __( 'Entity Type dimension', 'wordlift' ), |
|
233 | + 'description' => __('Entity Type dimension', 'wordlift'), |
|
234 | 234 | ) |
235 | 235 | ); |
236 | 236 | |
@@ -247,16 +247,16 @@ discard block |
||
247 | 247 | * @return int |
248 | 248 | * @since 3.21.0 |
249 | 249 | */ |
250 | - public function validate_entity_uri( $uri ) { |
|
250 | + public function validate_entity_uri($uri) { |
|
251 | 251 | // Basic validation is to ensure number is between 1 and 20. |
252 | 252 | // NOTE: certain analytics accounts have a much higher value - as many |
253 | 253 | // as 200 are allowed. |
254 | - if ( (int) $uri < 1 || (int) $uri > 20 ) { |
|
254 | + if ((int) $uri < 1 || (int) $uri > 20) { |
|
255 | 255 | // if we are out of range then pass the default value. |
256 | 256 | $uri = Wordlift_Configuration_Service::get_instance()->get_analytics_entity_uri_dimension(); |
257 | 257 | } |
258 | 258 | |
259 | - return absint( $uri ); |
|
259 | + return absint($uri); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -270,16 +270,16 @@ discard block |
||
270 | 270 | * @return int |
271 | 271 | * @since 3.21.0 |
272 | 272 | */ |
273 | - public function validate_entity_type( $type ) { |
|
273 | + public function validate_entity_type($type) { |
|
274 | 274 | // Basic validation is to ensure number is between 1 and 20. |
275 | 275 | // NOTE: certain analytics accounts have a much higher value - as many |
276 | 276 | // as 200 are allowed. |
277 | - if ( (int) $type < 1 || (int) $type > 20 ) { |
|
277 | + if ((int) $type < 1 || (int) $type > 20) { |
|
278 | 278 | // if we are out of range then pass the default value. |
279 | 279 | $type = Wordlift_Configuration_Service::get_instance()->get_analytics_entity_type_dimension(); |
280 | 280 | } |
281 | 281 | |
282 | - return absint( $type ); |
|
282 | + return absint($type); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
@@ -293,8 +293,8 @@ discard block |
||
293 | 293 | * @return array The sanitized input array. |
294 | 294 | * @since 3.21.0 |
295 | 295 | */ |
296 | - public function sanitize_callback( $input ) { |
|
297 | - if ( ! check_admin_referer( 'wl_analytics_settings-options' ) ) { |
|
296 | + public function sanitize_callback($input) { |
|
297 | + if ( ! check_admin_referer('wl_analytics_settings-options')) { |
|
298 | 298 | // Any failing nonce checks already die(). |
299 | 299 | return; |
300 | 300 | } |
@@ -303,19 +303,19 @@ discard block |
||
303 | 303 | * Validate and sanitize the $inputs and store them in $output saved. |
304 | 304 | */ |
305 | 305 | $output = array(); |
306 | - if ( isset( $input['analytics_enable'] ) ) { |
|
307 | - $output['analytics_enable'] = ( 'yes' === $input['analytics_enable'] ) ? 'yes' : 'no'; |
|
306 | + if (isset($input['analytics_enable'])) { |
|
307 | + $output['analytics_enable'] = ('yes' === $input['analytics_enable']) ? 'yes' : 'no'; |
|
308 | 308 | } |
309 | - if ( isset( $input['analytics_entity_uri_dimension'] ) ) { |
|
310 | - $output['analytics_entity_uri_dimension'] = (int) $this->validate_entity_uri( $input['analytics_entity_uri_dimension'] ); |
|
309 | + if (isset($input['analytics_entity_uri_dimension'])) { |
|
310 | + $output['analytics_entity_uri_dimension'] = (int) $this->validate_entity_uri($input['analytics_entity_uri_dimension']); |
|
311 | 311 | } |
312 | - if ( isset( $input['analytics_entity_type_dimension'] ) ) { |
|
312 | + if (isset($input['analytics_entity_type_dimension'])) { |
|
313 | 313 | // This dimension cannot be the same as the one set above. If it is |
314 | 314 | // then zero it out and it will fail validation. |
315 | - if ( isset( $output['analytics_entity_uri_dimension'] ) && $output['analytics_entity_uri_dimension'] === (int) $input['analytics_entity_type_dimension'] ) { |
|
315 | + if (isset($output['analytics_entity_uri_dimension']) && $output['analytics_entity_uri_dimension'] === (int) $input['analytics_entity_type_dimension']) { |
|
316 | 316 | $input['analytics_entity_type_dimension'] = 0; |
317 | 317 | } |
318 | - $output['analytics_entity_type_dimension'] = (int) $this->validate_entity_type( $input['analytics_entity_type_dimension'] ); |
|
318 | + $output['analytics_entity_type_dimension'] = (int) $this->validate_entity_type($input['analytics_entity_type_dimension']); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | // return items added to the output for saving. |
@@ -14,13 +14,13 @@ discard block |
||
14 | 14 | */ |
15 | 15 | function wl_register_metaboxes() { |
16 | 16 | |
17 | - new Wl_Metabox(); // Everything is done inside here with the correct timing. |
|
17 | + new Wl_Metabox(); // Everything is done inside here with the correct timing. |
|
18 | 18 | |
19 | 19 | } |
20 | 20 | |
21 | 21 | if ( is_admin() ) { |
22 | - add_action( 'load-post.php', 'wl_register_metaboxes' ); |
|
23 | - add_action( 'load-post-new.php', 'wl_register_metaboxes' ); |
|
22 | + add_action( 'load-post.php', 'wl_register_metaboxes' ); |
|
23 | + add_action( 'load-post-new.php', 'wl_register_metaboxes' ); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -31,41 +31,41 @@ discard block |
||
31 | 31 | */ |
32 | 32 | function wl_admin_add_entities_meta_box( $post_type, $post ) { |
33 | 33 | |
34 | - /* |
|
34 | + /* |
|
35 | 35 | * Call the `wl_can_see_classification_box` filter to determine whether we can display the classification box. |
36 | 36 | * |
37 | 37 | * @since 3.20.3 |
38 | 38 | * |
39 | 39 | * @see https://github.com/insideout10/wordlift-plugin/issues/914 |
40 | 40 | */ |
41 | - if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) { |
|
42 | - return; |
|
43 | - } |
|
44 | - |
|
45 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
46 | - if ( ! apply_filters( 'wl_feature__enable__classification-sidebar', true ) ) { |
|
47 | - return; |
|
48 | - } |
|
49 | - |
|
50 | - // Bail out if the post type doesn't support a TinyMCE editor. |
|
51 | - if ( ! wl_post_type_supports_editor( $post_type ) ) { |
|
52 | - return; |
|
53 | - } |
|
54 | - |
|
55 | - // If the editor is not gutenberg and not any other custom editor then we use the sidebar. |
|
56 | - if ( ! Wordlift_Admin::is_gutenberg() && ! No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( |
|
57 | - $post->ID |
|
58 | - ) ) { |
|
59 | - // Add main meta box for related entities and 4W only if not Gutenberg |
|
60 | - add_meta_box( |
|
61 | - 'wordlift_entities_box', |
|
62 | - __( 'WordLift', 'wordlift' ), |
|
63 | - 'wl_entities_box_content', |
|
64 | - $post_type, |
|
65 | - 'side', |
|
66 | - 'high' |
|
67 | - ); |
|
68 | - } |
|
41 | + if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) { |
|
42 | + return; |
|
43 | + } |
|
44 | + |
|
45 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
46 | + if ( ! apply_filters( 'wl_feature__enable__classification-sidebar', true ) ) { |
|
47 | + return; |
|
48 | + } |
|
49 | + |
|
50 | + // Bail out if the post type doesn't support a TinyMCE editor. |
|
51 | + if ( ! wl_post_type_supports_editor( $post_type ) ) { |
|
52 | + return; |
|
53 | + } |
|
54 | + |
|
55 | + // If the editor is not gutenberg and not any other custom editor then we use the sidebar. |
|
56 | + if ( ! Wordlift_Admin::is_gutenberg() && ! No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( |
|
57 | + $post->ID |
|
58 | + ) ) { |
|
59 | + // Add main meta box for related entities and 4W only if not Gutenberg |
|
60 | + add_meta_box( |
|
61 | + 'wordlift_entities_box', |
|
62 | + __( 'WordLift', 'wordlift' ), |
|
63 | + 'wl_entities_box_content', |
|
64 | + $post_type, |
|
65 | + 'side', |
|
66 | + 'high' |
|
67 | + ); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | } |
71 | 71 | |
@@ -82,18 +82,18 @@ discard block |
||
82 | 82 | */ |
83 | 83 | function wl_post_type_supports_editor( $post_type ) { |
84 | 84 | |
85 | - $default = post_type_supports( $post_type, 'editor' ); |
|
86 | - |
|
87 | - /** |
|
88 | - * Allow 3rd parties to force the classification to load. |
|
89 | - * |
|
90 | - * @param bool $default The preset value as gathered by the `post_type_supports` call. |
|
91 | - * |
|
92 | - * @see https://github.com/insideout10/wordlift-plugin/issues/847. |
|
93 | - * |
|
94 | - * @since 3.19.4 |
|
95 | - */ |
|
96 | - return apply_filters( 'wl_post_type_supports_editor', $default, $post_type ); |
|
85 | + $default = post_type_supports( $post_type, 'editor' ); |
|
86 | + |
|
87 | + /** |
|
88 | + * Allow 3rd parties to force the classification to load. |
|
89 | + * |
|
90 | + * @param bool $default The preset value as gathered by the `post_type_supports` call. |
|
91 | + * |
|
92 | + * @see https://github.com/insideout10/wordlift-plugin/issues/847. |
|
93 | + * |
|
94 | + * @since 3.19.4 |
|
95 | + */ |
|
96 | + return apply_filters( 'wl_post_type_supports_editor', $default, $post_type ); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -103,141 +103,141 @@ discard block |
||
103 | 103 | */ |
104 | 104 | function wl_entities_box_content( $post, $wrapper = true ) { |
105 | 105 | |
106 | - // Angularjs edit-post widget wrapper. |
|
107 | - if ( $wrapper ) { |
|
108 | - echo '<div id="wordlift-edit-post-outer-wrapper"></div>'; |
|
109 | - } |
|
106 | + // Angularjs edit-post widget wrapper. |
|
107 | + if ( $wrapper ) { |
|
108 | + echo '<div id="wordlift-edit-post-outer-wrapper"></div>'; |
|
109 | + } |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | function wl_entities_box_content_scripts() { |
113 | - $post = get_post(); |
|
113 | + $post = get_post(); |
|
114 | 114 | |
115 | - // Angularjs edit-post widget classification boxes configuration. |
|
116 | - // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize |
|
117 | - $classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES ); |
|
115 | + // Angularjs edit-post widget classification boxes configuration. |
|
116 | + // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize |
|
117 | + $classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES ); |
|
118 | 118 | |
119 | - // Array to store all related entities ids. |
|
120 | - $all_referenced_entities_ids = array(); |
|
119 | + // Array to store all related entities ids. |
|
120 | + $all_referenced_entities_ids = array(); |
|
121 | 121 | |
122 | - // Add selected entities to classification_boxes. |
|
123 | - foreach ( $classification_boxes as $i => $box ) { |
|
122 | + // Add selected entities to classification_boxes. |
|
123 | + foreach ( $classification_boxes as $i => $box ) { |
|
124 | 124 | |
125 | - // Get the entity referenced from the post content. |
|
126 | - /* |
|
125 | + // Get the entity referenced from the post content. |
|
126 | + /* |
|
127 | 127 | * Allow 3rd parties to provide another post content. |
128 | 128 | * |
129 | 129 | * @since 3.20.0 |
130 | 130 | */ |
131 | - $post_content = apply_filters( 'wl_post_content', $post->post_content, $post ); |
|
132 | - $entity_uris = Wordlift_Content_Filter_Service::get_instance()->get_entity_uris( $post_content ); |
|
133 | - |
|
134 | - // Enhance current box selected entities. |
|
135 | - $classification_boxes[ $i ]['selectedEntities'] = $entity_uris; |
|
136 | - |
|
137 | - // Maps the URIs to entity posts. |
|
138 | - $entity_service = Wordlift_Entity_Service::get_instance(); |
|
139 | - |
|
140 | - // Replace all entity URI's with post ID's if found or null if there is no related post. |
|
141 | - $entity_ids = array_map( |
|
142 | - function ( $item ) use ( $entity_service ) { |
|
143 | - // Return entity post by the entity URI or null. |
|
144 | - $post = $entity_service->get_entity_post_by_uri( $item ); |
|
145 | - |
|
146 | - // Check that the post object is not null. |
|
147 | - if ( ! empty( $post ) ) { |
|
148 | - return $post->ID; |
|
149 | - } |
|
150 | - }, |
|
151 | - $entity_uris |
|
152 | - ); |
|
153 | - // Store the entity ids for all the 4W. |
|
154 | - $all_referenced_entities_ids = array_merge( $all_referenced_entities_ids, $entity_ids ); |
|
155 | - |
|
156 | - } |
|
157 | - |
|
158 | - // Json encoding for classification boxes structure. |
|
159 | - $classification_boxes = wp_json_encode( $classification_boxes ); |
|
160 | - |
|
161 | - // Ensure there are no repetitions of the referenced entities. |
|
162 | - $all_referenced_entities_ids = array_unique( $all_referenced_entities_ids ); |
|
163 | - |
|
164 | - // Remove all null, false and empty strings. |
|
165 | - // NULL is being returned in some cases, when there is not related post, so we need to remove it. |
|
166 | - $all_referenced_entities_ids = array_filter( $all_referenced_entities_ids ); |
|
167 | - |
|
168 | - // Build the entity storage object. |
|
169 | - $referenced_entities_obj = array(); |
|
170 | - foreach ( $all_referenced_entities_ids as $referenced_entity ) { |
|
171 | - $entity = wl_serialize_entity( $referenced_entity ); |
|
172 | - // Set a default confidence of `PHP_INT_MAX` for already annotated entities. |
|
173 | - $referenced_entities_obj[ $entity['id'] ] = $entity |
|
174 | - + array( 'confidence' => PHP_INT_MAX ); |
|
175 | - } |
|
176 | - |
|
177 | - $referenced_entities_obj = empty( $referenced_entities_obj ) ? |
|
178 | - '{}' : wp_json_encode( $referenced_entities_obj ); |
|
179 | - |
|
180 | - $published_place_id = get_post_meta( |
|
181 | - $post->ID, |
|
182 | - Wordlift_Schema_Service::FIELD_LOCATION_CREATED, |
|
183 | - true |
|
184 | - ); |
|
185 | - $published_place_obj = ( $published_place_id ) ? |
|
186 | - wp_json_encode( wl_serialize_entity( $published_place_id ) ) : |
|
187 | - null; |
|
188 | - |
|
189 | - $topic_id = get_post_meta( |
|
190 | - $post->ID, |
|
191 | - Wordlift_Schema_Service::FIELD_TOPIC, |
|
192 | - true |
|
193 | - ); |
|
194 | - $topic_obj = ( $topic_id ) ? |
|
195 | - wp_json_encode( wl_serialize_entity( $topic_id ) ) : |
|
196 | - null; |
|
197 | - |
|
198 | - $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
199 | - |
|
200 | - $default_thumbnail_path = WL_DEFAULT_THUMBNAIL_PATH; |
|
201 | - $default_path = WL_DEFAULT_PATH; |
|
202 | - $dataset_uri = $configuration_service->get_dataset_uri(); |
|
203 | - $current_post_uri = Wordlift_Entity_Service::get_instance()->get_uri( $post->ID ); |
|
204 | - $is_entity = Wordlift_Entity_Service::get_instance()->is_entity( $post->ID ); |
|
205 | - |
|
206 | - // Retrieve the current post author. |
|
207 | - $post_author = get_userdata( $post->post_author )->display_name; |
|
208 | - // Retrive the published date. |
|
209 | - $published_date = get_the_time( 'Y-m-d', $post->ID ); |
|
210 | - // Current language. |
|
211 | - $current_language = $configuration_service->get_language_code(); |
|
212 | - $wordlift_timeline_shortcode = new Wordlift_Timeline_Shortcode(); |
|
213 | - $timelinejs_default_options = wp_json_encode( $wordlift_timeline_shortcode->get_timelinejs_default_options(), JSON_PRETTY_PRINT ); |
|
214 | - $addslashes_post_author = addslashes( $post_author ); |
|
215 | - |
|
216 | - $metabox_settings = array( |
|
217 | - 'classificationBoxes' => json_decode( $classification_boxes ), |
|
218 | - 'entities' => json_decode( $referenced_entities_obj ), |
|
219 | - 'currentPostId' => intval( $post->ID ), |
|
220 | - 'currentPostUri' => $current_post_uri, |
|
221 | - 'currentPostType' => $post->post_type, |
|
222 | - 'isEntity' => ! empty( $is_entity ), |
|
223 | - 'defaultThumbnailPath' => $default_thumbnail_path, |
|
224 | - 'defaultWordLiftPath' => $default_path, |
|
225 | - 'datasetUri' => $dataset_uri, |
|
226 | - 'currentUser' => $addslashes_post_author, |
|
227 | - 'publishedDate' => $published_date, |
|
228 | - 'publishedPlace' => $published_place_obj, |
|
229 | - 'topic' => json_decode( $topic_obj ), |
|
230 | - 'currentLanguage' => $current_language, |
|
231 | - 'timelinejsDefaultOptions' => json_decode( $timelinejs_default_options ), |
|
232 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
233 | - ); |
|
234 | - |
|
235 | - // Allow Classic and Block Editor scripts to register first. |
|
236 | - // Hook to the Block Editor script. |
|
237 | - wp_localize_script( 'wl-block-editor', '_wlMetaBoxSettings', array( 'settings' => $metabox_settings ) ); |
|
238 | - |
|
239 | - // Hook to the Classic Editor script, see Wordlift_Admin_Post_Edit_Page. |
|
240 | - wp_localize_script( 'wl-classic-editor', '_wlMetaBoxSettings', array( 'settings' => $metabox_settings ) ); |
|
131 | + $post_content = apply_filters( 'wl_post_content', $post->post_content, $post ); |
|
132 | + $entity_uris = Wordlift_Content_Filter_Service::get_instance()->get_entity_uris( $post_content ); |
|
133 | + |
|
134 | + // Enhance current box selected entities. |
|
135 | + $classification_boxes[ $i ]['selectedEntities'] = $entity_uris; |
|
136 | + |
|
137 | + // Maps the URIs to entity posts. |
|
138 | + $entity_service = Wordlift_Entity_Service::get_instance(); |
|
139 | + |
|
140 | + // Replace all entity URI's with post ID's if found or null if there is no related post. |
|
141 | + $entity_ids = array_map( |
|
142 | + function ( $item ) use ( $entity_service ) { |
|
143 | + // Return entity post by the entity URI or null. |
|
144 | + $post = $entity_service->get_entity_post_by_uri( $item ); |
|
145 | + |
|
146 | + // Check that the post object is not null. |
|
147 | + if ( ! empty( $post ) ) { |
|
148 | + return $post->ID; |
|
149 | + } |
|
150 | + }, |
|
151 | + $entity_uris |
|
152 | + ); |
|
153 | + // Store the entity ids for all the 4W. |
|
154 | + $all_referenced_entities_ids = array_merge( $all_referenced_entities_ids, $entity_ids ); |
|
155 | + |
|
156 | + } |
|
157 | + |
|
158 | + // Json encoding for classification boxes structure. |
|
159 | + $classification_boxes = wp_json_encode( $classification_boxes ); |
|
160 | + |
|
161 | + // Ensure there are no repetitions of the referenced entities. |
|
162 | + $all_referenced_entities_ids = array_unique( $all_referenced_entities_ids ); |
|
163 | + |
|
164 | + // Remove all null, false and empty strings. |
|
165 | + // NULL is being returned in some cases, when there is not related post, so we need to remove it. |
|
166 | + $all_referenced_entities_ids = array_filter( $all_referenced_entities_ids ); |
|
167 | + |
|
168 | + // Build the entity storage object. |
|
169 | + $referenced_entities_obj = array(); |
|
170 | + foreach ( $all_referenced_entities_ids as $referenced_entity ) { |
|
171 | + $entity = wl_serialize_entity( $referenced_entity ); |
|
172 | + // Set a default confidence of `PHP_INT_MAX` for already annotated entities. |
|
173 | + $referenced_entities_obj[ $entity['id'] ] = $entity |
|
174 | + + array( 'confidence' => PHP_INT_MAX ); |
|
175 | + } |
|
176 | + |
|
177 | + $referenced_entities_obj = empty( $referenced_entities_obj ) ? |
|
178 | + '{}' : wp_json_encode( $referenced_entities_obj ); |
|
179 | + |
|
180 | + $published_place_id = get_post_meta( |
|
181 | + $post->ID, |
|
182 | + Wordlift_Schema_Service::FIELD_LOCATION_CREATED, |
|
183 | + true |
|
184 | + ); |
|
185 | + $published_place_obj = ( $published_place_id ) ? |
|
186 | + wp_json_encode( wl_serialize_entity( $published_place_id ) ) : |
|
187 | + null; |
|
188 | + |
|
189 | + $topic_id = get_post_meta( |
|
190 | + $post->ID, |
|
191 | + Wordlift_Schema_Service::FIELD_TOPIC, |
|
192 | + true |
|
193 | + ); |
|
194 | + $topic_obj = ( $topic_id ) ? |
|
195 | + wp_json_encode( wl_serialize_entity( $topic_id ) ) : |
|
196 | + null; |
|
197 | + |
|
198 | + $configuration_service = Wordlift_Configuration_Service::get_instance(); |
|
199 | + |
|
200 | + $default_thumbnail_path = WL_DEFAULT_THUMBNAIL_PATH; |
|
201 | + $default_path = WL_DEFAULT_PATH; |
|
202 | + $dataset_uri = $configuration_service->get_dataset_uri(); |
|
203 | + $current_post_uri = Wordlift_Entity_Service::get_instance()->get_uri( $post->ID ); |
|
204 | + $is_entity = Wordlift_Entity_Service::get_instance()->is_entity( $post->ID ); |
|
205 | + |
|
206 | + // Retrieve the current post author. |
|
207 | + $post_author = get_userdata( $post->post_author )->display_name; |
|
208 | + // Retrive the published date. |
|
209 | + $published_date = get_the_time( 'Y-m-d', $post->ID ); |
|
210 | + // Current language. |
|
211 | + $current_language = $configuration_service->get_language_code(); |
|
212 | + $wordlift_timeline_shortcode = new Wordlift_Timeline_Shortcode(); |
|
213 | + $timelinejs_default_options = wp_json_encode( $wordlift_timeline_shortcode->get_timelinejs_default_options(), JSON_PRETTY_PRINT ); |
|
214 | + $addslashes_post_author = addslashes( $post_author ); |
|
215 | + |
|
216 | + $metabox_settings = array( |
|
217 | + 'classificationBoxes' => json_decode( $classification_boxes ), |
|
218 | + 'entities' => json_decode( $referenced_entities_obj ), |
|
219 | + 'currentPostId' => intval( $post->ID ), |
|
220 | + 'currentPostUri' => $current_post_uri, |
|
221 | + 'currentPostType' => $post->post_type, |
|
222 | + 'isEntity' => ! empty( $is_entity ), |
|
223 | + 'defaultThumbnailPath' => $default_thumbnail_path, |
|
224 | + 'defaultWordLiftPath' => $default_path, |
|
225 | + 'datasetUri' => $dataset_uri, |
|
226 | + 'currentUser' => $addslashes_post_author, |
|
227 | + 'publishedDate' => $published_date, |
|
228 | + 'publishedPlace' => $published_place_obj, |
|
229 | + 'topic' => json_decode( $topic_obj ), |
|
230 | + 'currentLanguage' => $current_language, |
|
231 | + 'timelinejsDefaultOptions' => json_decode( $timelinejs_default_options ), |
|
232 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
233 | + ); |
|
234 | + |
|
235 | + // Allow Classic and Block Editor scripts to register first. |
|
236 | + // Hook to the Block Editor script. |
|
237 | + wp_localize_script( 'wl-block-editor', '_wlMetaBoxSettings', array( 'settings' => $metabox_settings ) ); |
|
238 | + |
|
239 | + // Hook to the Classic Editor script, see Wordlift_Admin_Post_Edit_Page. |
|
240 | + wp_localize_script( 'wl-classic-editor', '_wlMetaBoxSettings', array( 'settings' => $metabox_settings ) ); |
|
241 | 241 | |
242 | 242 | } |
243 | 243 |
@@ -14,13 +14,13 @@ discard block |
||
14 | 14 | */ |
15 | 15 | function wl_register_metaboxes() { |
16 | 16 | |
17 | - new Wl_Metabox(); // Everything is done inside here with the correct timing. |
|
17 | + new Wl_Metabox(); // Everything is done inside here with the correct timing. |
|
18 | 18 | |
19 | 19 | } |
20 | 20 | |
21 | -if ( is_admin() ) { |
|
22 | - add_action( 'load-post.php', 'wl_register_metaboxes' ); |
|
23 | - add_action( 'load-post-new.php', 'wl_register_metaboxes' ); |
|
21 | +if (is_admin()) { |
|
22 | + add_action('load-post.php', 'wl_register_metaboxes'); |
|
23 | + add_action('load-post-new.php', 'wl_register_metaboxes'); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * @param string $post_type The type of the current open post. |
30 | 30 | * @param WP_Post $post WordPress post. |
31 | 31 | */ |
32 | -function wl_admin_add_entities_meta_box( $post_type, $post ) { |
|
32 | +function wl_admin_add_entities_meta_box($post_type, $post) { |
|
33 | 33 | |
34 | 34 | /* |
35 | 35 | * Call the `wl_can_see_classification_box` filter to determine whether we can display the classification box. |
@@ -38,28 +38,28 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @see https://github.com/insideout10/wordlift-plugin/issues/914 |
40 | 40 | */ |
41 | - if ( ! apply_filters( 'wl_can_see_classification_box', true ) ) { |
|
41 | + if ( ! apply_filters('wl_can_see_classification_box', true)) { |
|
42 | 42 | return; |
43 | 43 | } |
44 | 44 | |
45 | 45 | // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
46 | - if ( ! apply_filters( 'wl_feature__enable__classification-sidebar', true ) ) { |
|
46 | + if ( ! apply_filters('wl_feature__enable__classification-sidebar', true)) { |
|
47 | 47 | return; |
48 | 48 | } |
49 | 49 | |
50 | 50 | // Bail out if the post type doesn't support a TinyMCE editor. |
51 | - if ( ! wl_post_type_supports_editor( $post_type ) ) { |
|
51 | + if ( ! wl_post_type_supports_editor($post_type)) { |
|
52 | 52 | return; |
53 | 53 | } |
54 | 54 | |
55 | 55 | // If the editor is not gutenberg and not any other custom editor then we use the sidebar. |
56 | 56 | if ( ! Wordlift_Admin::is_gutenberg() && ! No_Editor_Analysis_Feature::can_no_editor_analysis_be_used( |
57 | 57 | $post->ID |
58 | - ) ) { |
|
58 | + )) { |
|
59 | 59 | // Add main meta box for related entities and 4W only if not Gutenberg |
60 | 60 | add_meta_box( |
61 | 61 | 'wordlift_entities_box', |
62 | - __( 'WordLift', 'wordlift' ), |
|
62 | + __('WordLift', 'wordlift'), |
|
63 | 63 | 'wl_entities_box_content', |
64 | 64 | $post_type, |
65 | 65 | 'side', |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | |
70 | 70 | } |
71 | 71 | |
72 | -add_action( 'add_meta_boxes', 'wl_admin_add_entities_meta_box', 10, 2 ); |
|
72 | +add_action('add_meta_boxes', 'wl_admin_add_entities_meta_box', 10, 2); |
|
73 | 73 | |
74 | 74 | /** |
75 | 75 | * Whether the post type supports the editor UI. |
@@ -80,9 +80,9 @@ discard block |
||
80 | 80 | * |
81 | 81 | * @return bool True if the editor UI is supported otherwise false. |
82 | 82 | */ |
83 | -function wl_post_type_supports_editor( $post_type ) { |
|
83 | +function wl_post_type_supports_editor($post_type) { |
|
84 | 84 | |
85 | - $default = post_type_supports( $post_type, 'editor' ); |
|
85 | + $default = post_type_supports($post_type, 'editor'); |
|
86 | 86 | |
87 | 87 | /** |
88 | 88 | * Allow 3rd parties to force the classification to load. |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * |
94 | 94 | * @since 3.19.4 |
95 | 95 | */ |
96 | - return apply_filters( 'wl_post_type_supports_editor', $default, $post_type ); |
|
96 | + return apply_filters('wl_post_type_supports_editor', $default, $post_type); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | /** |
@@ -101,10 +101,10 @@ discard block |
||
101 | 101 | * |
102 | 102 | * @param WP_Post $post The current post. |
103 | 103 | */ |
104 | -function wl_entities_box_content( $post, $wrapper = true ) { |
|
104 | +function wl_entities_box_content($post, $wrapper = true) { |
|
105 | 105 | |
106 | 106 | // Angularjs edit-post widget wrapper. |
107 | - if ( $wrapper ) { |
|
107 | + if ($wrapper) { |
|
108 | 108 | echo '<div id="wordlift-edit-post-outer-wrapper"></div>'; |
109 | 109 | } |
110 | 110 | } |
@@ -114,13 +114,13 @@ discard block |
||
114 | 114 | |
115 | 115 | // Angularjs edit-post widget classification boxes configuration. |
116 | 116 | // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize |
117 | - $classification_boxes = unserialize( WL_CORE_POST_CLASSIFICATION_BOXES ); |
|
117 | + $classification_boxes = unserialize(WL_CORE_POST_CLASSIFICATION_BOXES); |
|
118 | 118 | |
119 | 119 | // Array to store all related entities ids. |
120 | 120 | $all_referenced_entities_ids = array(); |
121 | 121 | |
122 | 122 | // Add selected entities to classification_boxes. |
123 | - foreach ( $classification_boxes as $i => $box ) { |
|
123 | + foreach ($classification_boxes as $i => $box) { |
|
124 | 124 | |
125 | 125 | // Get the entity referenced from the post content. |
126 | 126 | /* |
@@ -128,118 +128,116 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @since 3.20.0 |
130 | 130 | */ |
131 | - $post_content = apply_filters( 'wl_post_content', $post->post_content, $post ); |
|
132 | - $entity_uris = Wordlift_Content_Filter_Service::get_instance()->get_entity_uris( $post_content ); |
|
131 | + $post_content = apply_filters('wl_post_content', $post->post_content, $post); |
|
132 | + $entity_uris = Wordlift_Content_Filter_Service::get_instance()->get_entity_uris($post_content); |
|
133 | 133 | |
134 | 134 | // Enhance current box selected entities. |
135 | - $classification_boxes[ $i ]['selectedEntities'] = $entity_uris; |
|
135 | + $classification_boxes[$i]['selectedEntities'] = $entity_uris; |
|
136 | 136 | |
137 | 137 | // Maps the URIs to entity posts. |
138 | 138 | $entity_service = Wordlift_Entity_Service::get_instance(); |
139 | 139 | |
140 | 140 | // Replace all entity URI's with post ID's if found or null if there is no related post. |
141 | 141 | $entity_ids = array_map( |
142 | - function ( $item ) use ( $entity_service ) { |
|
142 | + function($item) use ($entity_service) { |
|
143 | 143 | // Return entity post by the entity URI or null. |
144 | - $post = $entity_service->get_entity_post_by_uri( $item ); |
|
144 | + $post = $entity_service->get_entity_post_by_uri($item); |
|
145 | 145 | |
146 | 146 | // Check that the post object is not null. |
147 | - if ( ! empty( $post ) ) { |
|
147 | + if ( ! empty($post)) { |
|
148 | 148 | return $post->ID; |
149 | 149 | } |
150 | 150 | }, |
151 | 151 | $entity_uris |
152 | 152 | ); |
153 | 153 | // Store the entity ids for all the 4W. |
154 | - $all_referenced_entities_ids = array_merge( $all_referenced_entities_ids, $entity_ids ); |
|
154 | + $all_referenced_entities_ids = array_merge($all_referenced_entities_ids, $entity_ids); |
|
155 | 155 | |
156 | 156 | } |
157 | 157 | |
158 | 158 | // Json encoding for classification boxes structure. |
159 | - $classification_boxes = wp_json_encode( $classification_boxes ); |
|
159 | + $classification_boxes = wp_json_encode($classification_boxes); |
|
160 | 160 | |
161 | 161 | // Ensure there are no repetitions of the referenced entities. |
162 | - $all_referenced_entities_ids = array_unique( $all_referenced_entities_ids ); |
|
162 | + $all_referenced_entities_ids = array_unique($all_referenced_entities_ids); |
|
163 | 163 | |
164 | 164 | // Remove all null, false and empty strings. |
165 | 165 | // NULL is being returned in some cases, when there is not related post, so we need to remove it. |
166 | - $all_referenced_entities_ids = array_filter( $all_referenced_entities_ids ); |
|
166 | + $all_referenced_entities_ids = array_filter($all_referenced_entities_ids); |
|
167 | 167 | |
168 | 168 | // Build the entity storage object. |
169 | 169 | $referenced_entities_obj = array(); |
170 | - foreach ( $all_referenced_entities_ids as $referenced_entity ) { |
|
171 | - $entity = wl_serialize_entity( $referenced_entity ); |
|
170 | + foreach ($all_referenced_entities_ids as $referenced_entity) { |
|
171 | + $entity = wl_serialize_entity($referenced_entity); |
|
172 | 172 | // Set a default confidence of `PHP_INT_MAX` for already annotated entities. |
173 | - $referenced_entities_obj[ $entity['id'] ] = $entity |
|
174 | - + array( 'confidence' => PHP_INT_MAX ); |
|
173 | + $referenced_entities_obj[$entity['id']] = $entity |
|
174 | + + array('confidence' => PHP_INT_MAX); |
|
175 | 175 | } |
176 | 176 | |
177 | - $referenced_entities_obj = empty( $referenced_entities_obj ) ? |
|
178 | - '{}' : wp_json_encode( $referenced_entities_obj ); |
|
177 | + $referenced_entities_obj = empty($referenced_entities_obj) ? |
|
178 | + '{}' : wp_json_encode($referenced_entities_obj); |
|
179 | 179 | |
180 | - $published_place_id = get_post_meta( |
|
180 | + $published_place_id = get_post_meta( |
|
181 | 181 | $post->ID, |
182 | 182 | Wordlift_Schema_Service::FIELD_LOCATION_CREATED, |
183 | 183 | true |
184 | 184 | ); |
185 | - $published_place_obj = ( $published_place_id ) ? |
|
186 | - wp_json_encode( wl_serialize_entity( $published_place_id ) ) : |
|
187 | - null; |
|
185 | + $published_place_obj = ($published_place_id) ? |
|
186 | + wp_json_encode(wl_serialize_entity($published_place_id)) : null; |
|
188 | 187 | |
189 | - $topic_id = get_post_meta( |
|
188 | + $topic_id = get_post_meta( |
|
190 | 189 | $post->ID, |
191 | 190 | Wordlift_Schema_Service::FIELD_TOPIC, |
192 | 191 | true |
193 | 192 | ); |
194 | - $topic_obj = ( $topic_id ) ? |
|
195 | - wp_json_encode( wl_serialize_entity( $topic_id ) ) : |
|
196 | - null; |
|
193 | + $topic_obj = ($topic_id) ? |
|
194 | + wp_json_encode(wl_serialize_entity($topic_id)) : null; |
|
197 | 195 | |
198 | 196 | $configuration_service = Wordlift_Configuration_Service::get_instance(); |
199 | 197 | |
200 | 198 | $default_thumbnail_path = WL_DEFAULT_THUMBNAIL_PATH; |
201 | 199 | $default_path = WL_DEFAULT_PATH; |
202 | 200 | $dataset_uri = $configuration_service->get_dataset_uri(); |
203 | - $current_post_uri = Wordlift_Entity_Service::get_instance()->get_uri( $post->ID ); |
|
204 | - $is_entity = Wordlift_Entity_Service::get_instance()->is_entity( $post->ID ); |
|
201 | + $current_post_uri = Wordlift_Entity_Service::get_instance()->get_uri($post->ID); |
|
202 | + $is_entity = Wordlift_Entity_Service::get_instance()->is_entity($post->ID); |
|
205 | 203 | |
206 | 204 | // Retrieve the current post author. |
207 | - $post_author = get_userdata( $post->post_author )->display_name; |
|
205 | + $post_author = get_userdata($post->post_author)->display_name; |
|
208 | 206 | // Retrive the published date. |
209 | - $published_date = get_the_time( 'Y-m-d', $post->ID ); |
|
207 | + $published_date = get_the_time('Y-m-d', $post->ID); |
|
210 | 208 | // Current language. |
211 | 209 | $current_language = $configuration_service->get_language_code(); |
212 | 210 | $wordlift_timeline_shortcode = new Wordlift_Timeline_Shortcode(); |
213 | - $timelinejs_default_options = wp_json_encode( $wordlift_timeline_shortcode->get_timelinejs_default_options(), JSON_PRETTY_PRINT ); |
|
214 | - $addslashes_post_author = addslashes( $post_author ); |
|
211 | + $timelinejs_default_options = wp_json_encode($wordlift_timeline_shortcode->get_timelinejs_default_options(), JSON_PRETTY_PRINT); |
|
212 | + $addslashes_post_author = addslashes($post_author); |
|
215 | 213 | |
216 | 214 | $metabox_settings = array( |
217 | - 'classificationBoxes' => json_decode( $classification_boxes ), |
|
218 | - 'entities' => json_decode( $referenced_entities_obj ), |
|
219 | - 'currentPostId' => intval( $post->ID ), |
|
215 | + 'classificationBoxes' => json_decode($classification_boxes), |
|
216 | + 'entities' => json_decode($referenced_entities_obj), |
|
217 | + 'currentPostId' => intval($post->ID), |
|
220 | 218 | 'currentPostUri' => $current_post_uri, |
221 | 219 | 'currentPostType' => $post->post_type, |
222 | - 'isEntity' => ! empty( $is_entity ), |
|
220 | + 'isEntity' => ! empty($is_entity), |
|
223 | 221 | 'defaultThumbnailPath' => $default_thumbnail_path, |
224 | 222 | 'defaultWordLiftPath' => $default_path, |
225 | 223 | 'datasetUri' => $dataset_uri, |
226 | 224 | 'currentUser' => $addslashes_post_author, |
227 | 225 | 'publishedDate' => $published_date, |
228 | 226 | 'publishedPlace' => $published_place_obj, |
229 | - 'topic' => json_decode( $topic_obj ), |
|
227 | + 'topic' => json_decode($topic_obj), |
|
230 | 228 | 'currentLanguage' => $current_language, |
231 | - 'timelinejsDefaultOptions' => json_decode( $timelinejs_default_options ), |
|
232 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
229 | + 'timelinejsDefaultOptions' => json_decode($timelinejs_default_options), |
|
230 | + 'ajax_url' => admin_url('admin-ajax.php'), |
|
233 | 231 | ); |
234 | 232 | |
235 | 233 | // Allow Classic and Block Editor scripts to register first. |
236 | 234 | // Hook to the Block Editor script. |
237 | - wp_localize_script( 'wl-block-editor', '_wlMetaBoxSettings', array( 'settings' => $metabox_settings ) ); |
|
235 | + wp_localize_script('wl-block-editor', '_wlMetaBoxSettings', array('settings' => $metabox_settings)); |
|
238 | 236 | |
239 | 237 | // Hook to the Classic Editor script, see Wordlift_Admin_Post_Edit_Page. |
240 | - wp_localize_script( 'wl-classic-editor', '_wlMetaBoxSettings', array( 'settings' => $metabox_settings ) ); |
|
238 | + wp_localize_script('wl-classic-editor', '_wlMetaBoxSettings', array('settings' => $metabox_settings)); |
|
241 | 239 | |
242 | 240 | } |
243 | 241 | |
244 | -add_action( 'admin_print_scripts-post.php', 'wl_entities_box_content_scripts', 11 ); |
|
245 | -add_action( 'admin_print_scripts-post-new.php', 'wl_entities_box_content_scripts', 11 ); |
|
242 | +add_action('admin_print_scripts-post.php', 'wl_entities_box_content_scripts', 11); |
|
243 | +add_action('admin_print_scripts-post-new.php', 'wl_entities_box_content_scripts', 11); |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | */ |
14 | 14 | |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -28,126 +28,126 @@ discard block |
||
28 | 28 | */ |
29 | 29 | class Wordlift_Admin_Setup { |
30 | 30 | |
31 | - /** |
|
32 | - * A {@link Wordlift_Key_Validation_Service} instance. |
|
33 | - * |
|
34 | - * @since 3.9.0 |
|
35 | - * @access private |
|
36 | - * @var Wordlift_Key_Validation_Service A {@link Wordlift_Key_Validation_Service} instance. |
|
37 | - */ |
|
38 | - private $key_validation_service; |
|
39 | - |
|
40 | - /** |
|
41 | - * A {@link Wordlift_Entity_Service} instance. |
|
42 | - * |
|
43 | - * @since 3.9.0 |
|
44 | - * @access private |
|
45 | - * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
46 | - */ |
|
47 | - private $entity_service; |
|
48 | - |
|
49 | - /** |
|
50 | - * A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
51 | - * |
|
52 | - * @since 3.20.0 |
|
53 | - * @access private |
|
54 | - * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
55 | - */ |
|
56 | - private $language_select_element; |
|
57 | - |
|
58 | - /** |
|
59 | - * A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
60 | - * |
|
61 | - * @since 3.20.0 |
|
62 | - * @access private |
|
63 | - * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
64 | - */ |
|
65 | - private $country_select_element; |
|
66 | - |
|
67 | - /** |
|
68 | - * Initialize the class and set its properties. |
|
69 | - * |
|
70 | - * @param \Wordlift_Key_Validation_Service $key_validation_service A {@link Wordlift_Key_Validation_Service} instance. |
|
71 | - * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
72 | - * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
73 | - * @param \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
74 | - * |
|
75 | - * @since 3.9.0 |
|
76 | - */ |
|
77 | - public function __construct( $key_validation_service, $entity_service, $language_select_element, $country_select_element ) { |
|
78 | - |
|
79 | - // Set a reference to the key validation service. |
|
80 | - $this->key_validation_service = $key_validation_service; |
|
81 | - |
|
82 | - // Set a reference to the entity service. |
|
83 | - $this->entity_service = $entity_service; |
|
84 | - |
|
85 | - // Set a reference to the UI elements language and country. |
|
86 | - $this->language_select_element = $language_select_element; |
|
87 | - $this->country_select_element = $country_select_element; |
|
88 | - |
|
89 | - // Hook to some WP's events: |
|
90 | - // When WP is loaded check whether the user decided to skip the set-up, i.e. don't show us even if WL is not set up. |
|
91 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
92 | - |
|
93 | - // Hook to `admin_menu` in order to add our own setup wizard page. |
|
94 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
95 | - |
|
96 | - // Triggered when the user accesses the admin area, we decide whether to show our own wizard. |
|
97 | - add_action( 'admin_init', array( $this, 'show_page' ) ); |
|
98 | - |
|
99 | - /** |
|
100 | - * Filter: wl_feature__enable__notices. |
|
101 | - * |
|
102 | - * @param bool whether the notices needs to be enabled or not. |
|
103 | - * |
|
104 | - * @return bool |
|
105 | - * @since 3.27.6 |
|
106 | - */ |
|
107 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
108 | - // Hook to `admin_notices` to display our notices. |
|
109 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Hook to `admin_init` and redirect to WordLift's setup page if the `_wl_activation_redirect` transient flag is set. |
|
115 | - * |
|
116 | - * @since 3.9.0 |
|
117 | - */ |
|
118 | - public function admin_init() { |
|
119 | - |
|
120 | - // If the `_wl_activation_redirect` is set, the redirect to the setup page. |
|
121 | - if ( get_transient( '_wl_activation_redirect' ) ) { |
|
122 | - delete_transient( '_wl_activation_redirect' ); |
|
123 | - |
|
124 | - // If the user asked to skip the wizard then comply. |
|
125 | - if ( Wordlift_Configuration_Service::get_instance()->is_skip_wizard() ) { |
|
126 | - return; |
|
127 | - } |
|
128 | - |
|
129 | - // If we're already on the page or the user doesn't have permissions, return. |
|
130 | - if ( ( ! empty( $_GET['page'] ) && 'wl-setup' === $_GET['page'] ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
131 | - return; |
|
132 | - } |
|
133 | - |
|
134 | - // Finally redirect to the setup page. |
|
135 | - wp_safe_redirect( admin_url( 'index.php?page=wl-setup' ) ); |
|
136 | - |
|
137 | - exit; |
|
138 | - } |
|
139 | - |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Generate an admin notice suggesting to start the wizard if there is no configuration. |
|
144 | - * |
|
145 | - * @since 3.9.0 |
|
146 | - */ |
|
147 | - public function admin_notices() { |
|
148 | - |
|
149 | - // Use `wl_configuration_get_key` to check whether WL's key is set and that the user didn't disable the wizard. |
|
150 | - if ( '' === Wordlift_Configuration_Service::get_instance()->get_key() && ! Wordlift_Configuration_Service::get_instance()->is_skip_wizard() ) { ?> |
|
31 | + /** |
|
32 | + * A {@link Wordlift_Key_Validation_Service} instance. |
|
33 | + * |
|
34 | + * @since 3.9.0 |
|
35 | + * @access private |
|
36 | + * @var Wordlift_Key_Validation_Service A {@link Wordlift_Key_Validation_Service} instance. |
|
37 | + */ |
|
38 | + private $key_validation_service; |
|
39 | + |
|
40 | + /** |
|
41 | + * A {@link Wordlift_Entity_Service} instance. |
|
42 | + * |
|
43 | + * @since 3.9.0 |
|
44 | + * @access private |
|
45 | + * @var Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
46 | + */ |
|
47 | + private $entity_service; |
|
48 | + |
|
49 | + /** |
|
50 | + * A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
51 | + * |
|
52 | + * @since 3.20.0 |
|
53 | + * @access private |
|
54 | + * @var \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
55 | + */ |
|
56 | + private $language_select_element; |
|
57 | + |
|
58 | + /** |
|
59 | + * A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
60 | + * |
|
61 | + * @since 3.20.0 |
|
62 | + * @access private |
|
63 | + * @var \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
64 | + */ |
|
65 | + private $country_select_element; |
|
66 | + |
|
67 | + /** |
|
68 | + * Initialize the class and set its properties. |
|
69 | + * |
|
70 | + * @param \Wordlift_Key_Validation_Service $key_validation_service A {@link Wordlift_Key_Validation_Service} instance. |
|
71 | + * @param \Wordlift_Entity_Service $entity_service A {@link Wordlift_Entity_Service} instance. |
|
72 | + * @param \Wordlift_Admin_Language_Select_Element $language_select_element A {@link Wordlift_Admin_Language_Select_Element} element renderer. |
|
73 | + * @param \Wordlift_Admin_Country_Select_Element $country_select_element A {@link Wordlift_Admin_Country_Select_Element} element renderer. |
|
74 | + * |
|
75 | + * @since 3.9.0 |
|
76 | + */ |
|
77 | + public function __construct( $key_validation_service, $entity_service, $language_select_element, $country_select_element ) { |
|
78 | + |
|
79 | + // Set a reference to the key validation service. |
|
80 | + $this->key_validation_service = $key_validation_service; |
|
81 | + |
|
82 | + // Set a reference to the entity service. |
|
83 | + $this->entity_service = $entity_service; |
|
84 | + |
|
85 | + // Set a reference to the UI elements language and country. |
|
86 | + $this->language_select_element = $language_select_element; |
|
87 | + $this->country_select_element = $country_select_element; |
|
88 | + |
|
89 | + // Hook to some WP's events: |
|
90 | + // When WP is loaded check whether the user decided to skip the set-up, i.e. don't show us even if WL is not set up. |
|
91 | + add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
92 | + |
|
93 | + // Hook to `admin_menu` in order to add our own setup wizard page. |
|
94 | + add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
95 | + |
|
96 | + // Triggered when the user accesses the admin area, we decide whether to show our own wizard. |
|
97 | + add_action( 'admin_init', array( $this, 'show_page' ) ); |
|
98 | + |
|
99 | + /** |
|
100 | + * Filter: wl_feature__enable__notices. |
|
101 | + * |
|
102 | + * @param bool whether the notices needs to be enabled or not. |
|
103 | + * |
|
104 | + * @return bool |
|
105 | + * @since 3.27.6 |
|
106 | + */ |
|
107 | + if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
108 | + // Hook to `admin_notices` to display our notices. |
|
109 | + add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Hook to `admin_init` and redirect to WordLift's setup page if the `_wl_activation_redirect` transient flag is set. |
|
115 | + * |
|
116 | + * @since 3.9.0 |
|
117 | + */ |
|
118 | + public function admin_init() { |
|
119 | + |
|
120 | + // If the `_wl_activation_redirect` is set, the redirect to the setup page. |
|
121 | + if ( get_transient( '_wl_activation_redirect' ) ) { |
|
122 | + delete_transient( '_wl_activation_redirect' ); |
|
123 | + |
|
124 | + // If the user asked to skip the wizard then comply. |
|
125 | + if ( Wordlift_Configuration_Service::get_instance()->is_skip_wizard() ) { |
|
126 | + return; |
|
127 | + } |
|
128 | + |
|
129 | + // If we're already on the page or the user doesn't have permissions, return. |
|
130 | + if ( ( ! empty( $_GET['page'] ) && 'wl-setup' === $_GET['page'] ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
131 | + return; |
|
132 | + } |
|
133 | + |
|
134 | + // Finally redirect to the setup page. |
|
135 | + wp_safe_redirect( admin_url( 'index.php?page=wl-setup' ) ); |
|
136 | + |
|
137 | + exit; |
|
138 | + } |
|
139 | + |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Generate an admin notice suggesting to start the wizard if there is no configuration. |
|
144 | + * |
|
145 | + * @since 3.9.0 |
|
146 | + */ |
|
147 | + public function admin_notices() { |
|
148 | + |
|
149 | + // Use `wl_configuration_get_key` to check whether WL's key is set and that the user didn't disable the wizard. |
|
150 | + if ( '' === Wordlift_Configuration_Service::get_instance()->get_key() && ! Wordlift_Configuration_Service::get_instance()->is_skip_wizard() ) { ?> |
|
151 | 151 | <div id="wl-message" class="updated"> |
152 | 152 | <p><?php esc_html_e( 'Welcome to WordLift – You‘re almost ready to start', 'wordlift' ); ?></p> |
153 | 153 | <p class="submit"> |
@@ -158,138 +158,138 @@ discard block |
||
158 | 158 | </p> |
159 | 159 | </div> |
160 | 160 | <?php |
161 | - } |
|
162 | - |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Handle hiding the wizard notices by user request. |
|
167 | - * |
|
168 | - * @since 3.9.0 |
|
169 | - */ |
|
170 | - public function hide_notices() { |
|
171 | - |
|
172 | - // If it's not a `wl-hide-notice` or the nonce is not set, return. |
|
173 | - if ( ! isset( $_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'] ) ) { |
|
174 | - return; |
|
175 | - } |
|
176 | - |
|
177 | - // If the nonce is invalid, return an error. |
|
178 | - if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wl_notice_nonce'] ) ), 'wordlift_hide_notices_nonce' ) ) { |
|
179 | - wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'wordlift' ) ); |
|
180 | - } |
|
181 | - |
|
182 | - // If the user doesn't have the right privileges, return an error. |
|
183 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
184 | - wp_die( esc_html__( 'Cheatin’ huh?', 'wordlift' ) ); |
|
185 | - } |
|
186 | - |
|
187 | - // Store a flag telling to skip the wizard. |
|
188 | - Wordlift_Configuration_Service::get_instance()->set_skip_wizard( true ); |
|
189 | - |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Register the wizard page to be able to access it. |
|
194 | - * |
|
195 | - * @since 3.9.0 |
|
196 | - */ |
|
197 | - public function admin_menu() { |
|
198 | - /** |
|
199 | - * |
|
200 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1209 |
|
201 | - * @since 3.27.7 |
|
202 | - */ |
|
203 | - // @todo: find another way to do this, since this is adding an empty space in WP's dashboard menu. |
|
204 | - add_dashboard_page( '', '', 'manage_options', 'wl-setup', '' ); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Displays the wizard page. |
|
209 | - * |
|
210 | - * @since 3.9.0 |
|
211 | - */ |
|
212 | - public function show_page() { |
|
213 | - |
|
214 | - // First check if we are in the wizard page at all, if not do nothing. |
|
215 | - if ( empty( $_GET['page'] ) || 'wl-setup' !== $_GET['page'] ) { |
|
216 | - return; |
|
217 | - } |
|
218 | - |
|
219 | - // If it's a POST and the `wl-save-configuration` action is set, save the configuration. |
|
220 | - if ( isset( $_POST['action'] ) && 'wl-save-configuration' === $_POST['action'] ) { |
|
221 | - |
|
222 | - // Check the nonce and the user capabilities. |
|
223 | - check_admin_referer( 'wl-save-configuration' ); |
|
224 | - |
|
225 | - // Check if the user has the right privileges. |
|
226 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
227 | - wp_die( esc_html__( 'Sorry, you do not have a permission to save the settings', 'wordlift' ) ); |
|
228 | - } |
|
229 | - |
|
230 | - // Save the configuration. |
|
231 | - $this->save_configuration( $_POST ); |
|
232 | - |
|
233 | - // Redirect to the admin's page. |
|
234 | - wp_safe_redirect( admin_url() ); |
|
235 | - exit(); |
|
236 | - } |
|
161 | + } |
|
162 | + |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Handle hiding the wizard notices by user request. |
|
167 | + * |
|
168 | + * @since 3.9.0 |
|
169 | + */ |
|
170 | + public function hide_notices() { |
|
171 | + |
|
172 | + // If it's not a `wl-hide-notice` or the nonce is not set, return. |
|
173 | + if ( ! isset( $_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'] ) ) { |
|
174 | + return; |
|
175 | + } |
|
176 | + |
|
177 | + // If the nonce is invalid, return an error. |
|
178 | + if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wl_notice_nonce'] ) ), 'wordlift_hide_notices_nonce' ) ) { |
|
179 | + wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'wordlift' ) ); |
|
180 | + } |
|
181 | + |
|
182 | + // If the user doesn't have the right privileges, return an error. |
|
183 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
184 | + wp_die( esc_html__( 'Cheatin’ huh?', 'wordlift' ) ); |
|
185 | + } |
|
186 | + |
|
187 | + // Store a flag telling to skip the wizard. |
|
188 | + Wordlift_Configuration_Service::get_instance()->set_skip_wizard( true ); |
|
189 | + |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Register the wizard page to be able to access it. |
|
194 | + * |
|
195 | + * @since 3.9.0 |
|
196 | + */ |
|
197 | + public function admin_menu() { |
|
198 | + /** |
|
199 | + * |
|
200 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1209 |
|
201 | + * @since 3.27.7 |
|
202 | + */ |
|
203 | + // @todo: find another way to do this, since this is adding an empty space in WP's dashboard menu. |
|
204 | + add_dashboard_page( '', '', 'manage_options', 'wl-setup', '' ); |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Displays the wizard page. |
|
209 | + * |
|
210 | + * @since 3.9.0 |
|
211 | + */ |
|
212 | + public function show_page() { |
|
213 | + |
|
214 | + // First check if we are in the wizard page at all, if not do nothing. |
|
215 | + if ( empty( $_GET['page'] ) || 'wl-setup' !== $_GET['page'] ) { |
|
216 | + return; |
|
217 | + } |
|
218 | + |
|
219 | + // If it's a POST and the `wl-save-configuration` action is set, save the configuration. |
|
220 | + if ( isset( $_POST['action'] ) && 'wl-save-configuration' === $_POST['action'] ) { |
|
221 | + |
|
222 | + // Check the nonce and the user capabilities. |
|
223 | + check_admin_referer( 'wl-save-configuration' ); |
|
224 | + |
|
225 | + // Check if the user has the right privileges. |
|
226 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
227 | + wp_die( esc_html__( 'Sorry, you do not have a permission to save the settings', 'wordlift' ) ); |
|
228 | + } |
|
229 | + |
|
230 | + // Save the configuration. |
|
231 | + $this->save_configuration( $_POST ); |
|
232 | + |
|
233 | + // Redirect to the admin's page. |
|
234 | + wp_safe_redirect( admin_url() ); |
|
235 | + exit(); |
|
236 | + } |
|
237 | 237 | |
238 | 238 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
239 | - $language_select = $this->language_select_element; |
|
240 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
241 | - $country_select = $this->country_select_element; |
|
239 | + $language_select = $this->language_select_element; |
|
240 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
241 | + $country_select = $this->country_select_element; |
|
242 | 242 | |
243 | - include plugin_dir_path( __DIR__ ) . 'admin/partials/wordlift-admin-setup.php'; |
|
243 | + include plugin_dir_path( __DIR__ ) . 'admin/partials/wordlift-admin-setup.php'; |
|
244 | 244 | |
245 | - exit; |
|
246 | - } |
|
245 | + exit; |
|
246 | + } |
|
247 | 247 | |
248 | - /** |
|
249 | - * Save WordLift's configuration using the provided parameters. |
|
250 | - * |
|
251 | - * @param array $params An array of configuration parameters. |
|
252 | - * |
|
253 | - * @since 3.9.0 |
|
254 | - */ |
|
255 | - public function save_configuration( $params ) { |
|
248 | + /** |
|
249 | + * Save WordLift's configuration using the provided parameters. |
|
250 | + * |
|
251 | + * @param array $params An array of configuration parameters. |
|
252 | + * |
|
253 | + * @since 3.9.0 |
|
254 | + */ |
|
255 | + public function save_configuration( $params ) { |
|
256 | 256 | |
257 | - // We have the following parameters: |
|
258 | - // `key`, holding WL's key, |
|
259 | - // `vocabulary`, holding the vocabulary path, |
|
260 | - // `wl-country-code` with the country code (e.g. `us`), |
|
261 | - // `share-diagnostic`, the user preferences about sharing data with us. |
|
262 | - // `user_type`, the user type either `personal` or `company`, |
|
263 | - // `name`, with the `personal` or `company`'s name, |
|
264 | - // `logo`, the attachment id for the `personal` or `company` entity. |
|
257 | + // We have the following parameters: |
|
258 | + // `key`, holding WL's key, |
|
259 | + // `vocabulary`, holding the vocabulary path, |
|
260 | + // `wl-country-code` with the country code (e.g. `us`), |
|
261 | + // `share-diagnostic`, the user preferences about sharing data with us. |
|
262 | + // `user_type`, the user type either `personal` or `company`, |
|
263 | + // `name`, with the `personal` or `company`'s name, |
|
264 | + // `logo`, the attachment id for the `personal` or `company` entity. |
|
265 | 265 | |
266 | - // Store the key: |
|
267 | - Wordlift_Configuration_Service::get_instance()->set_key( $params['key'] ); |
|
266 | + // Store the key: |
|
267 | + Wordlift_Configuration_Service::get_instance()->set_key( $params['key'] ); |
|
268 | 268 | |
269 | - // Store the vocabulary path: |
|
270 | - Wordlift_Configuration_Service::get_instance()->set_entity_base_path( $params['vocabulary'] ); |
|
269 | + // Store the vocabulary path: |
|
270 | + Wordlift_Configuration_Service::get_instance()->set_entity_base_path( $params['vocabulary'] ); |
|
271 | 271 | |
272 | - // Store the site's country: |
|
273 | - Wordlift_Configuration_Service::get_instance()->set_country_code( $params['wl-country-code'] ); |
|
272 | + // Store the site's country: |
|
273 | + Wordlift_Configuration_Service::get_instance()->set_country_code( $params['wl-country-code'] ); |
|
274 | 274 | |
275 | - // Store the preferences in variable, because if the checkbox is not checked |
|
276 | - // the `share-diagnostic` will not exists in `$params` array. |
|
277 | - $share_diagnostic_preferences = empty( $params['share-diagnostic'] ) ? 'no' : 'yes'; |
|
275 | + // Store the preferences in variable, because if the checkbox is not checked |
|
276 | + // the `share-diagnostic` will not exists in `$params` array. |
|
277 | + $share_diagnostic_preferences = empty( $params['share-diagnostic'] ) ? 'no' : 'yes'; |
|
278 | 278 | |
279 | - // Store the diagnostic preferences: |
|
280 | - Wordlift_Configuration_Service::get_instance()->set_diagnostic_preferences( $share_diagnostic_preferences ); |
|
279 | + // Store the diagnostic preferences: |
|
280 | + Wordlift_Configuration_Service::get_instance()->set_diagnostic_preferences( $share_diagnostic_preferences ); |
|
281 | 281 | |
282 | - // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
283 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person' ); |
|
282 | + // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
|
283 | + $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person' ); |
|
284 | 284 | |
285 | - // Create an entity for the publisher. |
|
286 | - $publisher_post_id = $this->entity_service->create( $params['name'], $type_uri, $params['logo'], 'publish' ); |
|
285 | + // Create an entity for the publisher. |
|
286 | + $publisher_post_id = $this->entity_service->create( $params['name'], $type_uri, $params['logo'], 'publish' ); |
|
287 | 287 | |
288 | - // Store the publisher entity post id in the configuration. |
|
289 | - Wordlift_Configuration_Service::get_instance()->set_publisher_id( $publisher_post_id ); |
|
288 | + // Store the publisher entity post id in the configuration. |
|
289 | + Wordlift_Configuration_Service::get_instance()->set_publisher_id( $publisher_post_id ); |
|
290 | 290 | |
291 | - flush_rewrite_rules(); // Needed because of possible change to the entity base path. |
|
291 | + flush_rewrite_rules(); // Needed because of possible change to the entity base path. |
|
292 | 292 | |
293 | - } |
|
293 | + } |
|
294 | 294 | |
295 | 295 | } |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * @since 3.9.0 |
13 | 13 | */ |
14 | 14 | |
15 | -if ( ! defined( 'ABSPATH' ) ) { |
|
15 | +if ( ! defined('ABSPATH')) { |
|
16 | 16 | exit; |
17 | 17 | } |
18 | 18 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @since 3.9.0 |
76 | 76 | */ |
77 | - public function __construct( $key_validation_service, $entity_service, $language_select_element, $country_select_element ) { |
|
77 | + public function __construct($key_validation_service, $entity_service, $language_select_element, $country_select_element) { |
|
78 | 78 | |
79 | 79 | // Set a reference to the key validation service. |
80 | 80 | $this->key_validation_service = $key_validation_service; |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | |
89 | 89 | // Hook to some WP's events: |
90 | 90 | // When WP is loaded check whether the user decided to skip the set-up, i.e. don't show us even if WL is not set up. |
91 | - add_action( 'wp_loaded', array( $this, 'hide_notices' ) ); |
|
91 | + add_action('wp_loaded', array($this, 'hide_notices')); |
|
92 | 92 | |
93 | 93 | // Hook to `admin_menu` in order to add our own setup wizard page. |
94 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
94 | + add_action('admin_menu', array($this, 'admin_menu')); |
|
95 | 95 | |
96 | 96 | // Triggered when the user accesses the admin area, we decide whether to show our own wizard. |
97 | - add_action( 'admin_init', array( $this, 'show_page' ) ); |
|
97 | + add_action('admin_init', array($this, 'show_page')); |
|
98 | 98 | |
99 | 99 | /** |
100 | 100 | * Filter: wl_feature__enable__notices. |
@@ -104,9 +104,9 @@ discard block |
||
104 | 104 | * @return bool |
105 | 105 | * @since 3.27.6 |
106 | 106 | */ |
107 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
107 | + if (apply_filters('wl_feature__enable__notices', true)) { |
|
108 | 108 | // Hook to `admin_notices` to display our notices. |
109 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
109 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
110 | 110 | } |
111 | 111 | } |
112 | 112 | |
@@ -118,21 +118,21 @@ discard block |
||
118 | 118 | public function admin_init() { |
119 | 119 | |
120 | 120 | // If the `_wl_activation_redirect` is set, the redirect to the setup page. |
121 | - if ( get_transient( '_wl_activation_redirect' ) ) { |
|
122 | - delete_transient( '_wl_activation_redirect' ); |
|
121 | + if (get_transient('_wl_activation_redirect')) { |
|
122 | + delete_transient('_wl_activation_redirect'); |
|
123 | 123 | |
124 | 124 | // If the user asked to skip the wizard then comply. |
125 | - if ( Wordlift_Configuration_Service::get_instance()->is_skip_wizard() ) { |
|
125 | + if (Wordlift_Configuration_Service::get_instance()->is_skip_wizard()) { |
|
126 | 126 | return; |
127 | 127 | } |
128 | 128 | |
129 | 129 | // If we're already on the page or the user doesn't have permissions, return. |
130 | - if ( ( ! empty( $_GET['page'] ) && 'wl-setup' === $_GET['page'] ) || is_network_admin() || isset( $_GET['activate-multi'] ) || ! current_user_can( 'manage_options' ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
130 | + if (( ! empty($_GET['page']) && 'wl-setup' === $_GET['page']) || is_network_admin() || isset($_GET['activate-multi']) || ! current_user_can('manage_options')) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
131 | 131 | return; |
132 | 132 | } |
133 | 133 | |
134 | 134 | // Finally redirect to the setup page. |
135 | - wp_safe_redirect( admin_url( 'index.php?page=wl-setup' ) ); |
|
135 | + wp_safe_redirect(admin_url('index.php?page=wl-setup')); |
|
136 | 136 | |
137 | 137 | exit; |
138 | 138 | } |
@@ -147,14 +147,14 @@ discard block |
||
147 | 147 | public function admin_notices() { |
148 | 148 | |
149 | 149 | // Use `wl_configuration_get_key` to check whether WL's key is set and that the user didn't disable the wizard. |
150 | - if ( '' === Wordlift_Configuration_Service::get_instance()->get_key() && ! Wordlift_Configuration_Service::get_instance()->is_skip_wizard() ) { ?> |
|
150 | + if ('' === Wordlift_Configuration_Service::get_instance()->get_key() && ! Wordlift_Configuration_Service::get_instance()->is_skip_wizard()) { ?> |
|
151 | 151 | <div id="wl-message" class="updated"> |
152 | - <p><?php esc_html_e( 'Welcome to WordLift – You‘re almost ready to start', 'wordlift' ); ?></p> |
|
152 | + <p><?php esc_html_e('Welcome to WordLift – You‘re almost ready to start', 'wordlift'); ?></p> |
|
153 | 153 | <p class="submit"> |
154 | - <a href="<?php echo esc_url( admin_url( 'admin.php?page=wl-setup' ) ); ?>" |
|
155 | - class="button-primary"><?php esc_html_e( 'Run the Setup Wizard', 'wordlift' ); ?></a> |
|
154 | + <a href="<?php echo esc_url(admin_url('admin.php?page=wl-setup')); ?>" |
|
155 | + class="button-primary"><?php esc_html_e('Run the Setup Wizard', 'wordlift'); ?></a> |
|
156 | 156 | <a class="button-secondary skip" |
157 | - href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'wl-hide-notice', 'install' ), 'wordlift_hide_notices_nonce', '_wl_notice_nonce' ) ); ?>"><?php esc_html_e( 'Skip Setup', 'wordlift' ); ?></a> |
|
157 | + href="<?php echo esc_url(wp_nonce_url(add_query_arg('wl-hide-notice', 'install'), 'wordlift_hide_notices_nonce', '_wl_notice_nonce')); ?>"><?php esc_html_e('Skip Setup', 'wordlift'); ?></a> |
|
158 | 158 | </p> |
159 | 159 | </div> |
160 | 160 | <?php |
@@ -170,22 +170,22 @@ discard block |
||
170 | 170 | public function hide_notices() { |
171 | 171 | |
172 | 172 | // If it's not a `wl-hide-notice` or the nonce is not set, return. |
173 | - if ( ! isset( $_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'] ) ) { |
|
173 | + if ( ! isset($_GET['wl-hide-notice'], $_GET['_wl_notice_nonce'])) { |
|
174 | 174 | return; |
175 | 175 | } |
176 | 176 | |
177 | 177 | // If the nonce is invalid, return an error. |
178 | - if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wl_notice_nonce'] ) ), 'wordlift_hide_notices_nonce' ) ) { |
|
179 | - wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'wordlift' ) ); |
|
178 | + if ( ! wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['_wl_notice_nonce'])), 'wordlift_hide_notices_nonce')) { |
|
179 | + wp_die(esc_html__('Action failed. Please refresh the page and retry.', 'wordlift')); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // If the user doesn't have the right privileges, return an error. |
183 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
184 | - wp_die( esc_html__( 'Cheatin’ huh?', 'wordlift' ) ); |
|
183 | + if ( ! current_user_can('manage_options')) { |
|
184 | + wp_die(esc_html__('Cheatin’ huh?', 'wordlift')); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | // Store a flag telling to skip the wizard. |
188 | - Wordlift_Configuration_Service::get_instance()->set_skip_wizard( true ); |
|
188 | + Wordlift_Configuration_Service::get_instance()->set_skip_wizard(true); |
|
189 | 189 | |
190 | 190 | } |
191 | 191 | |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @since 3.27.7 |
202 | 202 | */ |
203 | 203 | // @todo: find another way to do this, since this is adding an empty space in WP's dashboard menu. |
204 | - add_dashboard_page( '', '', 'manage_options', 'wl-setup', '' ); |
|
204 | + add_dashboard_page('', '', 'manage_options', 'wl-setup', ''); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -212,26 +212,26 @@ discard block |
||
212 | 212 | public function show_page() { |
213 | 213 | |
214 | 214 | // First check if we are in the wizard page at all, if not do nothing. |
215 | - if ( empty( $_GET['page'] ) || 'wl-setup' !== $_GET['page'] ) { |
|
215 | + if (empty($_GET['page']) || 'wl-setup' !== $_GET['page']) { |
|
216 | 216 | return; |
217 | 217 | } |
218 | 218 | |
219 | 219 | // If it's a POST and the `wl-save-configuration` action is set, save the configuration. |
220 | - if ( isset( $_POST['action'] ) && 'wl-save-configuration' === $_POST['action'] ) { |
|
220 | + if (isset($_POST['action']) && 'wl-save-configuration' === $_POST['action']) { |
|
221 | 221 | |
222 | 222 | // Check the nonce and the user capabilities. |
223 | - check_admin_referer( 'wl-save-configuration' ); |
|
223 | + check_admin_referer('wl-save-configuration'); |
|
224 | 224 | |
225 | 225 | // Check if the user has the right privileges. |
226 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
227 | - wp_die( esc_html__( 'Sorry, you do not have a permission to save the settings', 'wordlift' ) ); |
|
226 | + if ( ! current_user_can('manage_options')) { |
|
227 | + wp_die(esc_html__('Sorry, you do not have a permission to save the settings', 'wordlift')); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | // Save the configuration. |
231 | - $this->save_configuration( $_POST ); |
|
231 | + $this->save_configuration($_POST); |
|
232 | 232 | |
233 | 233 | // Redirect to the admin's page. |
234 | - wp_safe_redirect( admin_url() ); |
|
234 | + wp_safe_redirect(admin_url()); |
|
235 | 235 | exit(); |
236 | 236 | } |
237 | 237 | |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
241 | 241 | $country_select = $this->country_select_element; |
242 | 242 | |
243 | - include plugin_dir_path( __DIR__ ) . 'admin/partials/wordlift-admin-setup.php'; |
|
243 | + include plugin_dir_path(__DIR__).'admin/partials/wordlift-admin-setup.php'; |
|
244 | 244 | |
245 | 245 | exit; |
246 | 246 | } |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * |
253 | 253 | * @since 3.9.0 |
254 | 254 | */ |
255 | - public function save_configuration( $params ) { |
|
255 | + public function save_configuration($params) { |
|
256 | 256 | |
257 | 257 | // We have the following parameters: |
258 | 258 | // `key`, holding WL's key, |
@@ -264,29 +264,29 @@ discard block |
||
264 | 264 | // `logo`, the attachment id for the `personal` or `company` entity. |
265 | 265 | |
266 | 266 | // Store the key: |
267 | - Wordlift_Configuration_Service::get_instance()->set_key( $params['key'] ); |
|
267 | + Wordlift_Configuration_Service::get_instance()->set_key($params['key']); |
|
268 | 268 | |
269 | 269 | // Store the vocabulary path: |
270 | - Wordlift_Configuration_Service::get_instance()->set_entity_base_path( $params['vocabulary'] ); |
|
270 | + Wordlift_Configuration_Service::get_instance()->set_entity_base_path($params['vocabulary']); |
|
271 | 271 | |
272 | 272 | // Store the site's country: |
273 | - Wordlift_Configuration_Service::get_instance()->set_country_code( $params['wl-country-code'] ); |
|
273 | + Wordlift_Configuration_Service::get_instance()->set_country_code($params['wl-country-code']); |
|
274 | 274 | |
275 | 275 | // Store the preferences in variable, because if the checkbox is not checked |
276 | 276 | // the `share-diagnostic` will not exists in `$params` array. |
277 | - $share_diagnostic_preferences = empty( $params['share-diagnostic'] ) ? 'no' : 'yes'; |
|
277 | + $share_diagnostic_preferences = empty($params['share-diagnostic']) ? 'no' : 'yes'; |
|
278 | 278 | |
279 | 279 | // Store the diagnostic preferences: |
280 | - Wordlift_Configuration_Service::get_instance()->set_diagnostic_preferences( $share_diagnostic_preferences ); |
|
280 | + Wordlift_Configuration_Service::get_instance()->set_diagnostic_preferences($share_diagnostic_preferences); |
|
281 | 281 | |
282 | 282 | // Set the type URI, either http://schema.org/Person or http://schema.org/Organization. |
283 | - $type_uri = sprintf( 'http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person' ); |
|
283 | + $type_uri = sprintf('http://schema.org/%s', 'organization' === $params['user_type'] ? 'Organization' : 'Person'); |
|
284 | 284 | |
285 | 285 | // Create an entity for the publisher. |
286 | - $publisher_post_id = $this->entity_service->create( $params['name'], $type_uri, $params['logo'], 'publish' ); |
|
286 | + $publisher_post_id = $this->entity_service->create($params['name'], $type_uri, $params['logo'], 'publish'); |
|
287 | 287 | |
288 | 288 | // Store the publisher entity post id in the configuration. |
289 | - Wordlift_Configuration_Service::get_instance()->set_publisher_id( $publisher_post_id ); |
|
289 | + Wordlift_Configuration_Service::get_instance()->set_publisher_id($publisher_post_id); |
|
290 | 290 | |
291 | 291 | flush_rewrite_rules(); // Needed because of possible change to the entity base path. |
292 | 292 |
@@ -7,194 +7,194 @@ |
||
7 | 7 | */ |
8 | 8 | class Wordlift_Notice_Service { |
9 | 9 | |
10 | - /** |
|
11 | - * The template used to display notices. The <em>notice dismissible</em> style classes make this notice dismissible |
|
12 | - * on the WordPress UI (via a small X button on the right side of the notice). |
|
13 | - * |
|
14 | - * @since 3.2.0 |
|
15 | - */ |
|
16 | - const TEMPLATE = '<div class="wl-notice notice is-dismissible %s"><p>%s</p></div>'; |
|
17 | - |
|
18 | - /** |
|
19 | - * The standard WordPress <em>update</em> style class. |
|
20 | - * |
|
21 | - * @since 3.2.0 |
|
22 | - */ |
|
23 | - const UPDATE = 'update'; |
|
24 | - |
|
25 | - /** |
|
26 | - * The standard WordPress <em>update-nag</em> style class. |
|
27 | - * |
|
28 | - * @since 3.2.0 |
|
29 | - */ |
|
30 | - const UPDATE_NAG = 'update-nag'; |
|
31 | - |
|
32 | - /** |
|
33 | - * The standard WordPress <em>error</em> style class. |
|
34 | - * |
|
35 | - * @since 3.2.0 |
|
36 | - */ |
|
37 | - const ERROR = 'error'; |
|
38 | - |
|
39 | - /** |
|
40 | - * A custom WordLift css style class used for WordLift suggestions. |
|
41 | - * |
|
42 | - * @since 3.3.0 |
|
43 | - */ |
|
44 | - const SUGGESTION = 'wl-suggestion'; |
|
45 | - |
|
46 | - /** |
|
47 | - * The array of notices. |
|
48 | - * |
|
49 | - * @since 3.2.0 |
|
50 | - * @access private |
|
51 | - * @var array $notices The array of notices. |
|
52 | - */ |
|
53 | - private $notices = array(); |
|
54 | - |
|
55 | - /** |
|
56 | - * A singleton instance of the Notice service. |
|
57 | - * |
|
58 | - * @since 3.2.0 |
|
59 | - * @access private |
|
60 | - * @var \Wordlift_Notice_Service $instance A singleton instance of the Notice service. |
|
61 | - */ |
|
62 | - private static $instance; |
|
63 | - |
|
64 | - /** |
|
65 | - * Create an instance of the Notice service. |
|
66 | - * |
|
67 | - * @since 3.2.0 |
|
68 | - */ |
|
69 | - public function __construct() { |
|
70 | - /** |
|
71 | - * Filter: wl_feature__enable__notices. |
|
72 | - * |
|
73 | - * @param bool whether the notices needs to be enabled or not. |
|
74 | - * |
|
75 | - * @return bool |
|
76 | - * @since 3.27.6 |
|
77 | - */ |
|
78 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
79 | - // Hook to be called when to display notices. |
|
80 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
81 | - } |
|
82 | - self::$instance = $this; |
|
83 | - |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * Get the singleton instance of the Notice service. |
|
88 | - * |
|
89 | - * @return \Wordlift_Notice_Service The singleton instance of the Notice service. |
|
90 | - * @since 3.2.0 |
|
91 | - */ |
|
92 | - public static function get_instance() { |
|
93 | - |
|
94 | - return self::$instance; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Add a notice. |
|
99 | - * |
|
100 | - * @param string $class The css class. |
|
101 | - * @param string $message The message. |
|
102 | - * |
|
103 | - * @since 3.2.0 |
|
104 | - */ |
|
105 | - public function add( $class, $message ) { |
|
106 | - |
|
107 | - $this->notices[] = sprintf( self::TEMPLATE, $class, $this->transform( $message ) ); |
|
108 | - |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Add an update notice (message with a white background and a green left border). |
|
113 | - * |
|
114 | - * @param string $message The message to display. |
|
115 | - * |
|
116 | - * @since 3.2.0 |
|
117 | - */ |
|
118 | - public function add_update( $message ) { |
|
119 | - |
|
120 | - $this->add( self::UPDATE, $message ); |
|
121 | - |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Add an update nag notice (message with a white background and a yellow left border). |
|
126 | - * |
|
127 | - * @param string $message The message to display. |
|
128 | - * |
|
129 | - * @since 3.2.0 |
|
130 | - */ |
|
131 | - public function add_update_nag( $message ) { |
|
132 | - |
|
133 | - $this->add( self::UPDATE_NAG, $message ); |
|
134 | - |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Add an error notice (message with a white background and a red left border). |
|
139 | - * |
|
140 | - * @param string $message The message to display. |
|
141 | - * |
|
142 | - * @since 3.2.0 |
|
143 | - */ |
|
144 | - public function add_error( $message ) { |
|
145 | - |
|
146 | - $this->add( self::ERROR, $message ); |
|
147 | - |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Add a suggestion notice (message with a white background and a WordLift brand colored left border). |
|
152 | - * |
|
153 | - * @param string $message The message to display. |
|
154 | - * |
|
155 | - * @since 3.3.0 |
|
156 | - */ |
|
157 | - public function add_suggestion( $message ) { |
|
158 | - |
|
159 | - $this->add( self::SUGGESTION, $message ); |
|
160 | - |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Print out the notices when the admin_notices action is called. |
|
165 | - * |
|
166 | - * @since 3.2.0 |
|
167 | - */ |
|
168 | - public function admin_notices() { |
|
169 | - |
|
170 | - foreach ( $this->notices as $notice ) { |
|
171 | - echo wp_kses( |
|
172 | - $notice, |
|
173 | - array( |
|
174 | - 'div' => array( 'class' => array() ), |
|
175 | - 'p' => array(), |
|
176 | - ) |
|
177 | - ); |
|
178 | - } |
|
179 | - |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Transform message depending on message type. Return a string |
|
184 | - * |
|
185 | - * @param string $message The message. |
|
186 | - * |
|
187 | - * @since 3.3.0 |
|
188 | - */ |
|
189 | - private function transform( $message ) { |
|
190 | - |
|
191 | - switch ( gettype( $message ) ) { |
|
192 | - case 'array': |
|
193 | - return implode( '<br />', $message ); |
|
194 | - default: |
|
195 | - return $message; |
|
196 | - } |
|
197 | - |
|
198 | - } |
|
10 | + /** |
|
11 | + * The template used to display notices. The <em>notice dismissible</em> style classes make this notice dismissible |
|
12 | + * on the WordPress UI (via a small X button on the right side of the notice). |
|
13 | + * |
|
14 | + * @since 3.2.0 |
|
15 | + */ |
|
16 | + const TEMPLATE = '<div class="wl-notice notice is-dismissible %s"><p>%s</p></div>'; |
|
17 | + |
|
18 | + /** |
|
19 | + * The standard WordPress <em>update</em> style class. |
|
20 | + * |
|
21 | + * @since 3.2.0 |
|
22 | + */ |
|
23 | + const UPDATE = 'update'; |
|
24 | + |
|
25 | + /** |
|
26 | + * The standard WordPress <em>update-nag</em> style class. |
|
27 | + * |
|
28 | + * @since 3.2.0 |
|
29 | + */ |
|
30 | + const UPDATE_NAG = 'update-nag'; |
|
31 | + |
|
32 | + /** |
|
33 | + * The standard WordPress <em>error</em> style class. |
|
34 | + * |
|
35 | + * @since 3.2.0 |
|
36 | + */ |
|
37 | + const ERROR = 'error'; |
|
38 | + |
|
39 | + /** |
|
40 | + * A custom WordLift css style class used for WordLift suggestions. |
|
41 | + * |
|
42 | + * @since 3.3.0 |
|
43 | + */ |
|
44 | + const SUGGESTION = 'wl-suggestion'; |
|
45 | + |
|
46 | + /** |
|
47 | + * The array of notices. |
|
48 | + * |
|
49 | + * @since 3.2.0 |
|
50 | + * @access private |
|
51 | + * @var array $notices The array of notices. |
|
52 | + */ |
|
53 | + private $notices = array(); |
|
54 | + |
|
55 | + /** |
|
56 | + * A singleton instance of the Notice service. |
|
57 | + * |
|
58 | + * @since 3.2.0 |
|
59 | + * @access private |
|
60 | + * @var \Wordlift_Notice_Service $instance A singleton instance of the Notice service. |
|
61 | + */ |
|
62 | + private static $instance; |
|
63 | + |
|
64 | + /** |
|
65 | + * Create an instance of the Notice service. |
|
66 | + * |
|
67 | + * @since 3.2.0 |
|
68 | + */ |
|
69 | + public function __construct() { |
|
70 | + /** |
|
71 | + * Filter: wl_feature__enable__notices. |
|
72 | + * |
|
73 | + * @param bool whether the notices needs to be enabled or not. |
|
74 | + * |
|
75 | + * @return bool |
|
76 | + * @since 3.27.6 |
|
77 | + */ |
|
78 | + if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
79 | + // Hook to be called when to display notices. |
|
80 | + add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
81 | + } |
|
82 | + self::$instance = $this; |
|
83 | + |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * Get the singleton instance of the Notice service. |
|
88 | + * |
|
89 | + * @return \Wordlift_Notice_Service The singleton instance of the Notice service. |
|
90 | + * @since 3.2.0 |
|
91 | + */ |
|
92 | + public static function get_instance() { |
|
93 | + |
|
94 | + return self::$instance; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Add a notice. |
|
99 | + * |
|
100 | + * @param string $class The css class. |
|
101 | + * @param string $message The message. |
|
102 | + * |
|
103 | + * @since 3.2.0 |
|
104 | + */ |
|
105 | + public function add( $class, $message ) { |
|
106 | + |
|
107 | + $this->notices[] = sprintf( self::TEMPLATE, $class, $this->transform( $message ) ); |
|
108 | + |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Add an update notice (message with a white background and a green left border). |
|
113 | + * |
|
114 | + * @param string $message The message to display. |
|
115 | + * |
|
116 | + * @since 3.2.0 |
|
117 | + */ |
|
118 | + public function add_update( $message ) { |
|
119 | + |
|
120 | + $this->add( self::UPDATE, $message ); |
|
121 | + |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Add an update nag notice (message with a white background and a yellow left border). |
|
126 | + * |
|
127 | + * @param string $message The message to display. |
|
128 | + * |
|
129 | + * @since 3.2.0 |
|
130 | + */ |
|
131 | + public function add_update_nag( $message ) { |
|
132 | + |
|
133 | + $this->add( self::UPDATE_NAG, $message ); |
|
134 | + |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Add an error notice (message with a white background and a red left border). |
|
139 | + * |
|
140 | + * @param string $message The message to display. |
|
141 | + * |
|
142 | + * @since 3.2.0 |
|
143 | + */ |
|
144 | + public function add_error( $message ) { |
|
145 | + |
|
146 | + $this->add( self::ERROR, $message ); |
|
147 | + |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Add a suggestion notice (message with a white background and a WordLift brand colored left border). |
|
152 | + * |
|
153 | + * @param string $message The message to display. |
|
154 | + * |
|
155 | + * @since 3.3.0 |
|
156 | + */ |
|
157 | + public function add_suggestion( $message ) { |
|
158 | + |
|
159 | + $this->add( self::SUGGESTION, $message ); |
|
160 | + |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Print out the notices when the admin_notices action is called. |
|
165 | + * |
|
166 | + * @since 3.2.0 |
|
167 | + */ |
|
168 | + public function admin_notices() { |
|
169 | + |
|
170 | + foreach ( $this->notices as $notice ) { |
|
171 | + echo wp_kses( |
|
172 | + $notice, |
|
173 | + array( |
|
174 | + 'div' => array( 'class' => array() ), |
|
175 | + 'p' => array(), |
|
176 | + ) |
|
177 | + ); |
|
178 | + } |
|
179 | + |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Transform message depending on message type. Return a string |
|
184 | + * |
|
185 | + * @param string $message The message. |
|
186 | + * |
|
187 | + * @since 3.3.0 |
|
188 | + */ |
|
189 | + private function transform( $message ) { |
|
190 | + |
|
191 | + switch ( gettype( $message ) ) { |
|
192 | + case 'array': |
|
193 | + return implode( '<br />', $message ); |
|
194 | + default: |
|
195 | + return $message; |
|
196 | + } |
|
197 | + |
|
198 | + } |
|
199 | 199 | |
200 | 200 | } |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | * @return bool |
76 | 76 | * @since 3.27.6 |
77 | 77 | */ |
78 | - if ( apply_filters( 'wl_feature__enable__notices', true ) ) { |
|
78 | + if (apply_filters('wl_feature__enable__notices', true)) { |
|
79 | 79 | // Hook to be called when to display notices. |
80 | - add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
|
80 | + add_action('admin_notices', array($this, 'admin_notices')); |
|
81 | 81 | } |
82 | 82 | self::$instance = $this; |
83 | 83 | |
@@ -102,9 +102,9 @@ discard block |
||
102 | 102 | * |
103 | 103 | * @since 3.2.0 |
104 | 104 | */ |
105 | - public function add( $class, $message ) { |
|
105 | + public function add($class, $message) { |
|
106 | 106 | |
107 | - $this->notices[] = sprintf( self::TEMPLATE, $class, $this->transform( $message ) ); |
|
107 | + $this->notices[] = sprintf(self::TEMPLATE, $class, $this->transform($message)); |
|
108 | 108 | |
109 | 109 | } |
110 | 110 | |
@@ -115,9 +115,9 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @since 3.2.0 |
117 | 117 | */ |
118 | - public function add_update( $message ) { |
|
118 | + public function add_update($message) { |
|
119 | 119 | |
120 | - $this->add( self::UPDATE, $message ); |
|
120 | + $this->add(self::UPDATE, $message); |
|
121 | 121 | |
122 | 122 | } |
123 | 123 | |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | * |
129 | 129 | * @since 3.2.0 |
130 | 130 | */ |
131 | - public function add_update_nag( $message ) { |
|
131 | + public function add_update_nag($message) { |
|
132 | 132 | |
133 | - $this->add( self::UPDATE_NAG, $message ); |
|
133 | + $this->add(self::UPDATE_NAG, $message); |
|
134 | 134 | |
135 | 135 | } |
136 | 136 | |
@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @since 3.2.0 |
143 | 143 | */ |
144 | - public function add_error( $message ) { |
|
144 | + public function add_error($message) { |
|
145 | 145 | |
146 | - $this->add( self::ERROR, $message ); |
|
146 | + $this->add(self::ERROR, $message); |
|
147 | 147 | |
148 | 148 | } |
149 | 149 | |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | * |
155 | 155 | * @since 3.3.0 |
156 | 156 | */ |
157 | - public function add_suggestion( $message ) { |
|
157 | + public function add_suggestion($message) { |
|
158 | 158 | |
159 | - $this->add( self::SUGGESTION, $message ); |
|
159 | + $this->add(self::SUGGESTION, $message); |
|
160 | 160 | |
161 | 161 | } |
162 | 162 | |
@@ -167,11 +167,11 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function admin_notices() { |
169 | 169 | |
170 | - foreach ( $this->notices as $notice ) { |
|
170 | + foreach ($this->notices as $notice) { |
|
171 | 171 | echo wp_kses( |
172 | 172 | $notice, |
173 | 173 | array( |
174 | - 'div' => array( 'class' => array() ), |
|
174 | + 'div' => array('class' => array()), |
|
175 | 175 | 'p' => array(), |
176 | 176 | ) |
177 | 177 | ); |
@@ -186,11 +186,11 @@ discard block |
||
186 | 186 | * |
187 | 187 | * @since 3.3.0 |
188 | 188 | */ |
189 | - private function transform( $message ) { |
|
189 | + private function transform($message) { |
|
190 | 190 | |
191 | - switch ( gettype( $message ) ) { |
|
191 | + switch (gettype($message)) { |
|
192 | 192 | case 'array': |
193 | - return implode( '<br />', $message ); |
|
193 | + return implode('<br />', $message); |
|
194 | 194 | default: |
195 | 195 | return $message; |
196 | 196 | } |
@@ -18,133 +18,133 @@ |
||
18 | 18 | */ |
19 | 19 | abstract class Wordlift_Admin_Page { |
20 | 20 | |
21 | - /** |
|
22 | - * Define the {@link Wordlift_Admin_Page} constructor. |
|
23 | - * |
|
24 | - * @since 3.20.0 |
|
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - add_action( 'admin_menu', array( $this, 'admin_menu' ), 10, 0 ); |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * Get the parent slug. |
|
32 | - * |
|
33 | - * @return string The parent slug (default 'wl_admin_menu'). |
|
34 | - * @since 3.11.0 |
|
35 | - */ |
|
36 | - protected function get_parent_slug() { |
|
37 | - |
|
38 | - return 'wl_admin_menu'; |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Get the required capability. |
|
43 | - * |
|
44 | - * @return string The capability (default 'manage_options'). |
|
45 | - * @since 3.11.0 |
|
46 | - */ |
|
47 | - protected function get_capability() { |
|
48 | - |
|
49 | - return 'manage_options'; |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Get the page title. Will be translated. |
|
54 | - * |
|
55 | - * @return string The page title. |
|
56 | - * @since 3.11.0 |
|
57 | - */ |
|
58 | - abstract public function get_page_title(); |
|
59 | - |
|
60 | - /** |
|
61 | - * Get the menu title. Will be translated. |
|
62 | - * |
|
63 | - * @return string The menu title. |
|
64 | - * @since 3.11.0 |
|
65 | - */ |
|
66 | - abstract public function get_menu_title(); |
|
67 | - |
|
68 | - /** |
|
69 | - * Get the menu slug. |
|
70 | - * |
|
71 | - * @return string The menu slug. |
|
72 | - * @since 3.11.0 |
|
73 | - */ |
|
74 | - abstract public function get_menu_slug(); |
|
75 | - |
|
76 | - /** |
|
77 | - * Get the page url. |
|
78 | - * |
|
79 | - * @return string The escaped url of the admin page |
|
80 | - * @since 3.14.0 |
|
81 | - */ |
|
82 | - public function get_url() { |
|
83 | - |
|
84 | - // ideally should have used menu_page_url, but it is loaded later than some usages. |
|
85 | - $url = admin_url( 'admin.php?page=' . $this->get_menu_slug() ); |
|
86 | - |
|
87 | - return esc_url( $url ); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Get the partial file name, used in the {@link render} function. |
|
92 | - * |
|
93 | - * @return string The partial file name. |
|
94 | - * @since 3.11.0 |
|
95 | - */ |
|
96 | - abstract public function get_partial_name(); |
|
97 | - |
|
98 | - /** |
|
99 | - * The `admin_menu` callback. Will call {@link add_submenu_page} to add the |
|
100 | - * page to the admin menu. |
|
101 | - * |
|
102 | - * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
103 | - * @since 3.11.0 |
|
104 | - */ |
|
105 | - public function admin_menu() { |
|
106 | - // Add the sub-menu page. |
|
107 | - // |
|
108 | - // See http://codex.wordpress.org/Function_Reference/add_submenu_page |
|
109 | - $page = add_submenu_page( |
|
110 | - $this->get_parent_slug(), |
|
111 | - $this->get_page_title(), |
|
112 | - $this->get_menu_title(), |
|
113 | - $this->get_capability(), // The required capability, provided by the calling hook. |
|
114 | - $this->get_menu_slug(), |
|
115 | - array( $this, 'render' ) |
|
116 | - ); |
|
117 | - |
|
118 | - // Set a hook to enqueue scripts only when the settings page is displayed. |
|
119 | - add_action( |
|
120 | - 'admin_print_scripts-' . $page, |
|
121 | - array( |
|
122 | - $this, |
|
123 | - 'enqueue_scripts', |
|
124 | - ) |
|
125 | - ); |
|
126 | - |
|
127 | - // Finally return the page hook_suffix. |
|
128 | - return $page; |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Enqueue scripts for the specific page. Subclasses can override this function |
|
133 | - * to provide their own styles/scripts. |
|
134 | - * |
|
135 | - * @since 3.11.0 |
|
136 | - */ |
|
137 | - public function enqueue_scripts() { |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Render the page. |
|
142 | - */ |
|
143 | - public function render() { |
|
144 | - |
|
145 | - // Include the partial. |
|
146 | - include plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name(); |
|
147 | - |
|
148 | - } |
|
21 | + /** |
|
22 | + * Define the {@link Wordlift_Admin_Page} constructor. |
|
23 | + * |
|
24 | + * @since 3.20.0 |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + add_action( 'admin_menu', array( $this, 'admin_menu' ), 10, 0 ); |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * Get the parent slug. |
|
32 | + * |
|
33 | + * @return string The parent slug (default 'wl_admin_menu'). |
|
34 | + * @since 3.11.0 |
|
35 | + */ |
|
36 | + protected function get_parent_slug() { |
|
37 | + |
|
38 | + return 'wl_admin_menu'; |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Get the required capability. |
|
43 | + * |
|
44 | + * @return string The capability (default 'manage_options'). |
|
45 | + * @since 3.11.0 |
|
46 | + */ |
|
47 | + protected function get_capability() { |
|
48 | + |
|
49 | + return 'manage_options'; |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Get the page title. Will be translated. |
|
54 | + * |
|
55 | + * @return string The page title. |
|
56 | + * @since 3.11.0 |
|
57 | + */ |
|
58 | + abstract public function get_page_title(); |
|
59 | + |
|
60 | + /** |
|
61 | + * Get the menu title. Will be translated. |
|
62 | + * |
|
63 | + * @return string The menu title. |
|
64 | + * @since 3.11.0 |
|
65 | + */ |
|
66 | + abstract public function get_menu_title(); |
|
67 | + |
|
68 | + /** |
|
69 | + * Get the menu slug. |
|
70 | + * |
|
71 | + * @return string The menu slug. |
|
72 | + * @since 3.11.0 |
|
73 | + */ |
|
74 | + abstract public function get_menu_slug(); |
|
75 | + |
|
76 | + /** |
|
77 | + * Get the page url. |
|
78 | + * |
|
79 | + * @return string The escaped url of the admin page |
|
80 | + * @since 3.14.0 |
|
81 | + */ |
|
82 | + public function get_url() { |
|
83 | + |
|
84 | + // ideally should have used menu_page_url, but it is loaded later than some usages. |
|
85 | + $url = admin_url( 'admin.php?page=' . $this->get_menu_slug() ); |
|
86 | + |
|
87 | + return esc_url( $url ); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Get the partial file name, used in the {@link render} function. |
|
92 | + * |
|
93 | + * @return string The partial file name. |
|
94 | + * @since 3.11.0 |
|
95 | + */ |
|
96 | + abstract public function get_partial_name(); |
|
97 | + |
|
98 | + /** |
|
99 | + * The `admin_menu` callback. Will call {@link add_submenu_page} to add the |
|
100 | + * page to the admin menu. |
|
101 | + * |
|
102 | + * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
103 | + * @since 3.11.0 |
|
104 | + */ |
|
105 | + public function admin_menu() { |
|
106 | + // Add the sub-menu page. |
|
107 | + // |
|
108 | + // See http://codex.wordpress.org/Function_Reference/add_submenu_page |
|
109 | + $page = add_submenu_page( |
|
110 | + $this->get_parent_slug(), |
|
111 | + $this->get_page_title(), |
|
112 | + $this->get_menu_title(), |
|
113 | + $this->get_capability(), // The required capability, provided by the calling hook. |
|
114 | + $this->get_menu_slug(), |
|
115 | + array( $this, 'render' ) |
|
116 | + ); |
|
117 | + |
|
118 | + // Set a hook to enqueue scripts only when the settings page is displayed. |
|
119 | + add_action( |
|
120 | + 'admin_print_scripts-' . $page, |
|
121 | + array( |
|
122 | + $this, |
|
123 | + 'enqueue_scripts', |
|
124 | + ) |
|
125 | + ); |
|
126 | + |
|
127 | + // Finally return the page hook_suffix. |
|
128 | + return $page; |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Enqueue scripts for the specific page. Subclasses can override this function |
|
133 | + * to provide their own styles/scripts. |
|
134 | + * |
|
135 | + * @since 3.11.0 |
|
136 | + */ |
|
137 | + public function enqueue_scripts() { |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Render the page. |
|
142 | + */ |
|
143 | + public function render() { |
|
144 | + |
|
145 | + // Include the partial. |
|
146 | + include plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name(); |
|
147 | + |
|
148 | + } |
|
149 | 149 | |
150 | 150 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * @since 3.20.0 |
25 | 25 | */ |
26 | 26 | public function __construct() { |
27 | - add_action( 'admin_menu', array( $this, 'admin_menu' ), 10, 0 ); |
|
27 | + add_action('admin_menu', array($this, 'admin_menu'), 10, 0); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -82,9 +82,9 @@ discard block |
||
82 | 82 | public function get_url() { |
83 | 83 | |
84 | 84 | // ideally should have used menu_page_url, but it is loaded later than some usages. |
85 | - $url = admin_url( 'admin.php?page=' . $this->get_menu_slug() ); |
|
85 | + $url = admin_url('admin.php?page='.$this->get_menu_slug()); |
|
86 | 86 | |
87 | - return esc_url( $url ); |
|
87 | + return esc_url($url); |
|
88 | 88 | } |
89 | 89 | |
90 | 90 | /** |
@@ -110,14 +110,14 @@ discard block |
||
110 | 110 | $this->get_parent_slug(), |
111 | 111 | $this->get_page_title(), |
112 | 112 | $this->get_menu_title(), |
113 | - $this->get_capability(), // The required capability, provided by the calling hook. |
|
113 | + $this->get_capability(), // The required capability, provided by the calling hook. |
|
114 | 114 | $this->get_menu_slug(), |
115 | - array( $this, 'render' ) |
|
115 | + array($this, 'render') |
|
116 | 116 | ); |
117 | 117 | |
118 | 118 | // Set a hook to enqueue scripts only when the settings page is displayed. |
119 | 119 | add_action( |
120 | - 'admin_print_scripts-' . $page, |
|
120 | + 'admin_print_scripts-'.$page, |
|
121 | 121 | array( |
122 | 122 | $this, |
123 | 123 | 'enqueue_scripts', |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | public function render() { |
144 | 144 | |
145 | 145 | // Include the partial. |
146 | - include plugin_dir_path( __FILE__ ) . 'partials/' . $this->get_partial_name(); |
|
146 | + include plugin_dir_path(__FILE__).'partials/'.$this->get_partial_name(); |
|
147 | 147 | |
148 | 148 | } |
149 | 149 |