Completed
Pull Request — master (#1093)
by Naveen
02:48
created
src/admin/class-wordlift-admin-post-edit-page.php 1 patch
Indentation   +278 added lines, -278 removed lines patch added patch discarded remove patch
@@ -20,127 +20,127 @@  discard block
 block discarded – undo
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
-	 */
60
-	function __construct( $plugin ) {
61
-
62
-		$this->log = Wordlift_Log_Service::get_logger( get_class() );
63
-
64
-		add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_scripts_gutenberg', ) );
65
-
66
-		// Bail out if we're in the UX Builder editor.
67
-		if ( $this->is_ux_builder_editor() ) {
68
-			$this->log->info( 'WordLift will not show, since we are in UX Builder editor.' );
69
-
70
-			return;
71
-		}
72
-
73
-		// Define the callbacks.
74
-		$callback = array( $this, 'enqueue_scripts', );
75
-		// Set a hook to enqueue scripts only when the edit page is displayed.
76
-		add_action( 'admin_print_scripts-post.php', $callback );
77
-		add_action( 'admin_print_scripts-post-new.php', $callback );
78
-
79
-		$this->plugin = $plugin;
80
-	}
81
-
82
-	/**
83
-	 * Check whether the current post opens with G'berg or not.
84
-	 *
85
-	 * @return bool True if G'berg is used otherwise false.
86
-	 * @since 3.22.3
87
-	 */
88
-	function is_gutenberg_page() {
89
-		if ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) {
90
-			// The Gutenberg plugin is on.
91
-			return TRUE;
92
-		}
93
-
94
-		$current_screen = get_current_screen();
95
-		if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
96
-			// Gutenberg page on 5+.
97
-			return TRUE;
98
-		}
99
-
100
-		return FALSE;
101
-	}
102
-
103
-	/**
104
-	 * Check if we're in UX builder.
105
-	 *
106
-	 * @see   https://github.com/insideout10/wordlift-plugin/issues/691
107
-	 *
108
-	 * @since 3.15.4
109
-	 *
110
-	 * @return bool True if we're in UX builder, otherwise false.
111
-	 */
112
-	private function is_ux_builder_editor() {
113
-
114
-		return function_exists( 'ux_builder_is_editor' )
115
-		       && ux_builder_is_editor();
116
-	}
117
-
118
-	/**
119
-	 * Enqueue scripts and styles for the edit page.
120
-	 *
121
-	 * @since 3.11.0
122
-	 */
123
-	public function enqueue_scripts() {
124
-
125
-		// Bail out if this is G'berg.
126
-		if ( $this->is_gutenberg_page() ) {
127
-			return;
128
-		}
129
-
130
-		// Dequeue potentially conflicting ontrapages angular scripts which any *are not* used on the edit screen.
131
-		//
132
-		// @see https://github.com/insideout10/wordlift-plugin/issues/832
133
-		wp_dequeue_script( 'ontrapagesAngular' );
134
-		wp_dequeue_script( 'ontrapagesApp' );
135
-		wp_dequeue_script( 'ontrapagesController' );
136
-
137
-		// If Gutenberg is enabled for the post, do not load the legacy edit.js.
138
-		if ( function_exists( 'use_block_editor_for_post' ) && use_block_editor_for_post( get_post() ) ) {
139
-			return;
140
-		}
141
-
142
-
143
-		/*
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
+     */
60
+    function __construct( $plugin ) {
61
+
62
+        $this->log = Wordlift_Log_Service::get_logger( get_class() );
63
+
64
+        add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_scripts_gutenberg', ) );
65
+
66
+        // Bail out if we're in the UX Builder editor.
67
+        if ( $this->is_ux_builder_editor() ) {
68
+            $this->log->info( 'WordLift will not show, since we are in UX Builder editor.' );
69
+
70
+            return;
71
+        }
72
+
73
+        // Define the callbacks.
74
+        $callback = array( $this, 'enqueue_scripts', );
75
+        // Set a hook to enqueue scripts only when the edit page is displayed.
76
+        add_action( 'admin_print_scripts-post.php', $callback );
77
+        add_action( 'admin_print_scripts-post-new.php', $callback );
78
+
79
+        $this->plugin = $plugin;
80
+    }
81
+
82
+    /**
83
+     * Check whether the current post opens with G'berg or not.
84
+     *
85
+     * @return bool True if G'berg is used otherwise false.
86
+     * @since 3.22.3
87
+     */
88
+    function is_gutenberg_page() {
89
+        if ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) {
90
+            // The Gutenberg plugin is on.
91
+            return TRUE;
92
+        }
93
+
94
+        $current_screen = get_current_screen();
95
+        if ( method_exists( $current_screen, 'is_block_editor' ) && $current_screen->is_block_editor() ) {
96
+            // Gutenberg page on 5+.
97
+            return TRUE;
98
+        }
99
+
100
+        return FALSE;
101
+    }
102
+
103
+    /**
104
+     * Check if we're in UX builder.
105
+     *
106
+     * @see   https://github.com/insideout10/wordlift-plugin/issues/691
107
+     *
108
+     * @since 3.15.4
109
+     *
110
+     * @return bool True if we're in UX builder, otherwise false.
111
+     */
112
+    private function is_ux_builder_editor() {
113
+
114
+        return function_exists( 'ux_builder_is_editor' )
115
+               && ux_builder_is_editor();
116
+    }
117
+
118
+    /**
119
+     * Enqueue scripts and styles for the edit page.
120
+     *
121
+     * @since 3.11.0
122
+     */
123
+    public function enqueue_scripts() {
124
+
125
+        // Bail out if this is G'berg.
126
+        if ( $this->is_gutenberg_page() ) {
127
+            return;
128
+        }
129
+
130
+        // Dequeue potentially conflicting ontrapages angular scripts which any *are not* used on the edit screen.
131
+        //
132
+        // @see https://github.com/insideout10/wordlift-plugin/issues/832
133
+        wp_dequeue_script( 'ontrapagesAngular' );
134
+        wp_dequeue_script( 'ontrapagesApp' );
135
+        wp_dequeue_script( 'ontrapagesController' );
136
+
137
+        // If Gutenberg is enabled for the post, do not load the legacy edit.js.
138
+        if ( function_exists( 'use_block_editor_for_post' ) && use_block_editor_for_post( get_post() ) ) {
139
+            return;
140
+        }
141
+
142
+
143
+        /*
144 144
 		 * Enqueue the edit screen JavaScript. The `wordlift-admin.bundle.js` file
145 145
 		 * is scheduled to replace the older `wordlift-admin.min.js` once client-side
146 146
 		 * code is properly refactored.
@@ -149,170 +149,170 @@  discard block
 block discarded – undo
149 149
 		 *
150 150
 		 * @since 3.20.0 edit.js has been migrated to the new webpack configuration.
151 151
 		 */
152
-		$script_name = plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/edit';
153
-
154
-		/**
155
-		 * Scripts_Helper introduced.
156
-		 *
157
-		 * @since 3.25.0 Scripts are loaded using script helper to ensure WP 4.4 compatibiility.
158
-		 * @since 3.25.1 The handle is used to hook the wp_localize_script for the _wlEntityTypes global object.
159
-		 */
160
-		Scripts_Helper::enqueue_based_on_wordpress_version(
161
-			'wl-classic-editor',
162
-			$script_name,
163
-			array(
164
-				$this->plugin->get_plugin_name(),
165
-				'jquery',
166
-				// Require wp.ajax.
167
-				'wp-util',
168
-				// @@todo: provide the following dependencies when we're in WP < 5.0 (i.e. when these dependencies aren't already defined).
169
-				'react',
170
-				'react-dom',
171
-				'wp-element',
172
-				'wp-polyfill',
173
-				/*
152
+        $script_name = plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/edit';
153
+
154
+        /**
155
+         * Scripts_Helper introduced.
156
+         *
157
+         * @since 3.25.0 Scripts are loaded using script helper to ensure WP 4.4 compatibiility.
158
+         * @since 3.25.1 The handle is used to hook the wp_localize_script for the _wlEntityTypes global object.
159
+         */
160
+        Scripts_Helper::enqueue_based_on_wordpress_version(
161
+            'wl-classic-editor',
162
+            $script_name,
163
+            array(
164
+                $this->plugin->get_plugin_name(),
165
+                'jquery',
166
+                // Require wp.ajax.
167
+                'wp-util',
168
+                // @@todo: provide the following dependencies when we're in WP < 5.0 (i.e. when these dependencies aren't already defined).
169
+                'react',
170
+                'react-dom',
171
+                'wp-element',
172
+                'wp-polyfill',
173
+                /*
174 174
 				* Angular isn't loaded anymore remotely, but it is loaded within wordlift-reloaded.js.
175 175
 				*
176 176
 				* See https://github.com/insideout10/wordlift-plugin/issues/865.
177 177
 				*
178 178
 				* @since 3.19.6
179 179
 				*/
180
-				//				// Require Angular.
181
-				//				'wl-angular',
182
-				//				'wl-angular-geolocation',
183
-				//				'wl-angular-touch',
184
-				//				'wl-angular-animate',
185
-				/**
186
-				 * We need the `wp.hooks` global to allow the edit.js script to send actions.
187
-				 *
188
-				 * @since 3.23.0
189
-				 */
190
-				'wp-hooks',
191
-			)
192
-		);
193
-
194
-		wp_enqueue_style( 'wl-classic-editor', "$script_name.css", array(), $this->plugin->get_version() );
195
-		// Disable Faq Editor.
196
-		// $this->load_faq_scripts_and_styles();
197
-		// $this->load_faq_settings( self::TINY_MCE );
198
-	}
199
-
200
-	/**
201
-	 * Enqueue the scripts and styles needed for FAQ
202
-	 */
203
-	private function load_faq_scripts_and_styles() {
204
-		wp_enqueue_style(
205
-			'wl-faq-metabox-style',
206
-			plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/faq.css',
207
-			array()
208
-		);
209
-		Scripts_Helper::enqueue_based_on_wordpress_version(
210
-			'wl-faq-metabox-script',
211
-			plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/faq',
212
-			array( 'wp-polyfill' ),
213
-			true
214
-		);
215
-	}
216
-
217
-	/**
218
-	 * Get FAQ settings array
219
-	 *
220
-	 * @return array
221
-	 */
222
-	public function get_faq_settings() {
223
-		return array(
224
-			'restUrl'                 => get_rest_url( NULL, WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faq' ),
225
-			'listBoxId'               => self::FAQ_LIST_BOX_ID,
226
-			'nonce'                   => wp_create_nonce( 'wp_rest' ),
227
-			'postId'                  => get_the_ID(),
228
-			// Translation for warning, error message.
229
-			'invalidTagMessage'       => sprintf( __( 'Invalid tags %s is present in answer', self::WORDLIFT_TEXT_DOMAIN ), "{INVALID_TAGS}" ),
230
-			'invalidWordCountMessage' => sprintf( __( 'Answer word count must not exceed %s words', self::WORDLIFT_TEXT_DOMAIN ), "{ANSWER_WORD_COUNT_WARNING_LIMIT}" ),
231
-			'questionText'            => __( 'Question', self::WORDLIFT_TEXT_DOMAIN ),
232
-			'answerText'              => __( 'Answer', self::WORDLIFT_TEXT_DOMAIN ),
233
-			'addQuestionOrAnswerText' => __( 'Add Question / Answer', self::WORDLIFT_TEXT_DOMAIN ),
234
-			'addQuestionText'         => __( 'Add Question', self::WORDLIFT_TEXT_DOMAIN ),
235
-			'addAnswerText'           => __( 'Add Answer', self::WORDLIFT_TEXT_DOMAIN ),
236
-			'noFaqItemsText'          => __( 'Highlight a question in content, then click Add Question.', self::WORDLIFT_TEXT_DOMAIN ),
237
-			'updatingText'          => __( 'Updating...', self::WORDLIFT_TEXT_DOMAIN )
238
-		);
239
-	}
240
-
241
-	/**
242
-	 * Load FAQ settings to the add/edit post page
243
-	 *
244
-	 * @param $editor string specifying which text editor needed to be used.
245
-	 */
246
-	private function load_faq_settings( $editor ) {
247
-		// This script also provides translations to gutenberg.
248
-		wp_localize_script( 'wl-faq-metabox-script', '_wlFaqSettings', $this->get_faq_settings() );
249
-
250
-		// Enqueue the FAQ style
251
-		if ( $editor === self::GUTENBERG ) {
252
-			Scripts_Helper::enqueue_based_on_wordpress_version(
253
-				'wl-faq-gutenberg-plugin',
254
-				plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/block-editor-faq-plugin',
255
-				array( 'wp-polyfill' ),
256
-				TRUE
257
-			);
258
-		}
259
-	}
260
-
261
-	/**
262
-	 * Enqueue scripts and styles for the gutenberg edit page.
263
-	 *
264
-	 * @since 3.21.0
265
-	 */
266
-	public function enqueue_scripts_gutenberg() {
267
-		// Load FAQ settings. - Disabled for now
268
-		// $this->load_faq_scripts_and_styles();
269
-		//$this->load_faq_settings( self::GUTENBERG );
270
-
271
-		wp_register_script(
272
-			'wl-block-editor',
273
-			plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/block-editor.js',
274
-			array(
275
-				'react',
276
-				'wordlift',
277
-				'wp-hooks',
278
-				'wp-data',
279
-				'wp-rich-text',
280
-				'wp-blocks',
281
-				'wp-plugins',
282
-				'wp-edit-post',
283
-			),
284
-			$this->plugin->get_version()
285
-		);
286
-		wp_localize_script( 'wl-block-editor', '_wlBlockEditorSettings', array(
287
-			'root'  => esc_url_raw( rest_url() ),
288
-			'nonce' => wp_create_nonce( 'wp_rest' )
289
-		) );
290
-
291
-		/*
180
+                //				// Require Angular.
181
+                //				'wl-angular',
182
+                //				'wl-angular-geolocation',
183
+                //				'wl-angular-touch',
184
+                //				'wl-angular-animate',
185
+                /**
186
+                 * We need the `wp.hooks` global to allow the edit.js script to send actions.
187
+                 *
188
+                 * @since 3.23.0
189
+                 */
190
+                'wp-hooks',
191
+            )
192
+        );
193
+
194
+        wp_enqueue_style( 'wl-classic-editor', "$script_name.css", array(), $this->plugin->get_version() );
195
+        // Disable Faq Editor.
196
+        // $this->load_faq_scripts_and_styles();
197
+        // $this->load_faq_settings( self::TINY_MCE );
198
+    }
199
+
200
+    /**
201
+     * Enqueue the scripts and styles needed for FAQ
202
+     */
203
+    private function load_faq_scripts_and_styles() {
204
+        wp_enqueue_style(
205
+            'wl-faq-metabox-style',
206
+            plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/faq.css',
207
+            array()
208
+        );
209
+        Scripts_Helper::enqueue_based_on_wordpress_version(
210
+            'wl-faq-metabox-script',
211
+            plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/faq',
212
+            array( 'wp-polyfill' ),
213
+            true
214
+        );
215
+    }
216
+
217
+    /**
218
+     * Get FAQ settings array
219
+     *
220
+     * @return array
221
+     */
222
+    public function get_faq_settings() {
223
+        return array(
224
+            'restUrl'                 => get_rest_url( NULL, WL_REST_ROUTE_DEFAULT_NAMESPACE . '/faq' ),
225
+            'listBoxId'               => self::FAQ_LIST_BOX_ID,
226
+            'nonce'                   => wp_create_nonce( 'wp_rest' ),
227
+            'postId'                  => get_the_ID(),
228
+            // Translation for warning, error message.
229
+            'invalidTagMessage'       => sprintf( __( 'Invalid tags %s is present in answer', self::WORDLIFT_TEXT_DOMAIN ), "{INVALID_TAGS}" ),
230
+            'invalidWordCountMessage' => sprintf( __( 'Answer word count must not exceed %s words', self::WORDLIFT_TEXT_DOMAIN ), "{ANSWER_WORD_COUNT_WARNING_LIMIT}" ),
231
+            'questionText'            => __( 'Question', self::WORDLIFT_TEXT_DOMAIN ),
232
+            'answerText'              => __( 'Answer', self::WORDLIFT_TEXT_DOMAIN ),
233
+            'addQuestionOrAnswerText' => __( 'Add Question / Answer', self::WORDLIFT_TEXT_DOMAIN ),
234
+            'addQuestionText'         => __( 'Add Question', self::WORDLIFT_TEXT_DOMAIN ),
235
+            'addAnswerText'           => __( 'Add Answer', self::WORDLIFT_TEXT_DOMAIN ),
236
+            'noFaqItemsText'          => __( 'Highlight a question in content, then click Add Question.', self::WORDLIFT_TEXT_DOMAIN ),
237
+            'updatingText'          => __( 'Updating...', self::WORDLIFT_TEXT_DOMAIN )
238
+        );
239
+    }
240
+
241
+    /**
242
+     * Load FAQ settings to the add/edit post page
243
+     *
244
+     * @param $editor string specifying which text editor needed to be used.
245
+     */
246
+    private function load_faq_settings( $editor ) {
247
+        // This script also provides translations to gutenberg.
248
+        wp_localize_script( 'wl-faq-metabox-script', '_wlFaqSettings', $this->get_faq_settings() );
249
+
250
+        // Enqueue the FAQ style
251
+        if ( $editor === self::GUTENBERG ) {
252
+            Scripts_Helper::enqueue_based_on_wordpress_version(
253
+                'wl-faq-gutenberg-plugin',
254
+                plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/block-editor-faq-plugin',
255
+                array( 'wp-polyfill' ),
256
+                TRUE
257
+            );
258
+        }
259
+    }
260
+
261
+    /**
262
+     * Enqueue scripts and styles for the gutenberg edit page.
263
+     *
264
+     * @since 3.21.0
265
+     */
266
+    public function enqueue_scripts_gutenberg() {
267
+        // Load FAQ settings. - Disabled for now
268
+        // $this->load_faq_scripts_and_styles();
269
+        //$this->load_faq_settings( self::GUTENBERG );
270
+
271
+        wp_register_script(
272
+            'wl-block-editor',
273
+            plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/block-editor.js',
274
+            array(
275
+                'react',
276
+                'wordlift',
277
+                'wp-hooks',
278
+                'wp-data',
279
+                'wp-rich-text',
280
+                'wp-blocks',
281
+                'wp-plugins',
282
+                'wp-edit-post',
283
+            ),
284
+            $this->plugin->get_version()
285
+        );
286
+        wp_localize_script( 'wl-block-editor', '_wlBlockEditorSettings', array(
287
+            'root'  => esc_url_raw( rest_url() ),
288
+            'nonce' => wp_create_nonce( 'wp_rest' )
289
+        ) );
290
+
291
+        /*
292 292
 		 * @since 3.25.1 The hook is used by the wp_localize_script to register the _wlEntityTypes global object.
293 293
 		 */
294
-		wp_enqueue_style(
295
-			'wl-block-editor',
296
-			plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/block-editor.css',
297
-			array(),
298
-			$this->plugin->get_version()
299
-		);
300
-
301
-		wp_enqueue_script(
302
-			'wl-autocomplete-select',
303
-			plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/autocomplete-select.js',
304
-			array(),
305
-			$this->plugin->get_version(),
306
-			TRUE
307
-		);
308
-
309
-		wp_enqueue_style(
310
-			'wl-autocomplete-select',
311
-			plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/autocomplete-select.css',
312
-			array(),
313
-			$this->plugin->get_version()
314
-		);
315
-
316
-	}
294
+        wp_enqueue_style(
295
+            'wl-block-editor',
296
+            plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/block-editor.css',
297
+            array(),
298
+            $this->plugin->get_version()
299
+        );
300
+
301
+        wp_enqueue_script(
302
+            'wl-autocomplete-select',
303
+            plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/autocomplete-select.js',
304
+            array(),
305
+            $this->plugin->get_version(),
306
+            TRUE
307
+        );
308
+
309
+        wp_enqueue_style(
310
+            'wl-autocomplete-select',
311
+            plugin_dir_url( dirname( __FILE__ ) ) . 'js/dist/autocomplete-select.css',
312
+            array(),
313
+            $this->plugin->get_version()
314
+        );
315
+
316
+    }
317 317
 
318 318
 }
Please login to merge, or discard this patch.