@@ -10,24 +10,24 @@ discard block |
||
10 | 10 | |
11 | 11 | class assets { |
12 | 12 | |
13 | - public function __construct(){ |
|
13 | + public function __construct() { |
|
14 | 14 | |
15 | - add_action('wp_enqueue_scripts', array($this,'scripts')); |
|
15 | + add_action('wp_enqueue_scripts', array($this, 'scripts')); |
|
16 | 16 | } |
17 | 17 | |
18 | - public function scripts(){ |
|
18 | + public function scripts() { |
|
19 | 19 | |
20 | 20 | |
21 | 21 | global $post; |
22 | - if ( lasso_user_can('edit_posts') && |
|
23 | - !( function_exists( 'is_gutenberg_page' ) && has_blocks( $post->post_content) )) {// bail if the post has Gutenberg bloc |
|
22 | + if (lasso_user_can('edit_posts') && |
|
23 | + !(function_exists('is_gutenberg_page') && has_blocks($post->post_content))) {// bail if the post has Gutenberg bloc |
|
24 | 24 | |
25 | 25 | /** Returns the time offset from UTC |
26 | 26 | */ |
27 | 27 | function get_UTC_offset() { |
28 | - $timezone_string = get_option( 'timezone_string' ); |
|
29 | - if (empty( $timezone_string ) ) { |
|
30 | - return get_option('gmt_offset')*3600; |
|
28 | + $timezone_string = get_option('timezone_string'); |
|
29 | + if (empty($timezone_string)) { |
|
30 | + return get_option('gmt_offset') * 3600; |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | $origin_dtz = new \DateTimeZone($timezone_string); |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | wp_enqueue_style('lasso-style', LASSO_URL.'/public/assets/css/lasso.css', LASSO_VERSION, true); |
40 | 40 | |
41 | 41 | //don't load autocomplete if it's a stockholm theme |
42 | - $themename = wp_get_theme()->get('Name'); |
|
43 | - if ($themename !='Stockholm' ) { |
|
42 | + $themename = wp_get_theme()->get('Name'); |
|
43 | + if ($themename != 'Stockholm') { |
|
44 | 44 | wp_enqueue_script('jquery-ui-autocomplete'); |
45 | 45 | } |
46 | 46 | wp_enqueue_script('jquery-ui-draggable'); |
@@ -53,27 +53,27 @@ discard block |
||
53 | 53 | // url for json api |
54 | 54 | $home_url = function_exists('json_get_url_prefix') ? json_get_url_prefix() : false; |
55 | 55 | |
56 | - $article_object = lasso_editor_get_option('article_class','lasso_editor'); |
|
56 | + $article_object = lasso_editor_get_option('article_class', 'lasso_editor'); |
|
57 | 57 | |
58 | - $article_object = empty( $article_object ) && lasso_get_supported_theme_class() ? lasso_get_supported_theme_class() : $article_object; |
|
58 | + $article_object = empty($article_object) && lasso_get_supported_theme_class() ? lasso_get_supported_theme_class() : $article_object; |
|
59 | 59 | |
60 | - $featImgClass = lasso_editor_get_option('featimg_class','lasso_editor'); |
|
61 | - if (empty( $featImgClass )) { |
|
60 | + $featImgClass = lasso_editor_get_option('featimg_class', 'lasso_editor'); |
|
61 | + if (empty($featImgClass)) { |
|
62 | 62 | $featImgClass = lasso_get_supported_theme_featured_image_class(); |
63 | 63 | } |
64 | - $titleClass = lasso_editor_get_option('title_class','lasso_editor'); |
|
65 | - if (empty( $titleClass )) { |
|
64 | + $titleClass = lasso_editor_get_option('title_class', 'lasso_editor'); |
|
65 | + if (empty($titleClass)) { |
|
66 | 66 | $titleClass = lasso_get_supported_theme_title_class(); |
67 | 67 | } |
68 | - $toolbar_headings = lasso_editor_get_option('toolbar_headings', 'lasso_editor'); |
|
69 | - $toolbar_headings_h4 = lasso_editor_get_option('toolbar_headings_h4', 'lasso_editor'); |
|
68 | + $toolbar_headings = lasso_editor_get_option('toolbar_headings', 'lasso_editor'); |
|
69 | + $toolbar_headings_h4 = lasso_editor_get_option('toolbar_headings_h4', 'lasso_editor'); |
|
70 | 70 | $objectsNoSave = lasso_editor_get_option('dont_save', 'lasso_editor'); |
71 | - $objectsNonEditable = lasso_editor_get_option('non_editable', 'lasso_editor'); |
|
71 | + $objectsNonEditable = lasso_editor_get_option('non_editable', 'lasso_editor'); |
|
72 | 72 | $disableRESTSave = lasso_editor_get_option('save_using_rest_disabled', 'lasso_editor'); |
73 | - $save_to_post_disabled = lasso_editor_get_option( 'post_save_disabled', 'lasso_editor' ); |
|
73 | + $save_to_post_disabled = lasso_editor_get_option('post_save_disabled', 'lasso_editor'); |
|
74 | 74 | |
75 | - $bold_tag = lasso_editor_get_option('bold_tag', 'lasso_editor','b'); |
|
76 | - $i_tag = lasso_editor_get_option('i_tag', 'lasso_editor','i'); |
|
75 | + $bold_tag = lasso_editor_get_option('bold_tag', 'lasso_editor', 'b'); |
|
76 | + $i_tag = lasso_editor_get_option('i_tag', 'lasso_editor', 'i'); |
|
77 | 77 | |
78 | 78 | |
79 | 79 | //text alignement |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | |
88 | 88 | if ($show_color) { |
89 | 89 | //color picker |
90 | - wp_enqueue_style( 'wp-color-picker' ); |
|
91 | - wp_enqueue_script( 'iris', admin_url( 'js/iris.min.js' ), array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), false, 1 ); |
|
90 | + wp_enqueue_style('wp-color-picker'); |
|
91 | + wp_enqueue_script('iris', admin_url('js/iris.min.js'), array('jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch'), false, 1); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | // click to insert components, not drag and drop |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | |
98 | 98 | // custom fields |
99 | 99 | |
100 | - $custom_fields = apply_filters( 'editus_custom_fields', null ); //array('testFieldName' => '#field1'); |
|
100 | + $custom_fields = apply_filters('editus_custom_fields', null); //array('testFieldName' => '#field1'); |
|
101 | 101 | |
102 | 102 | |
103 | 103 | |
@@ -105,57 +105,57 @@ discard block |
||
105 | 105 | $postid = get_the_ID(); |
106 | 106 | $tz_offset = get_UTC_offset(); |
107 | 107 | $post_date = get_the_time('U', $postid); |
108 | - $time = (time()+$tz_offset); |
|
108 | + $time = (time() + $tz_offset); |
|
109 | 109 | $delta = $time - $post_date; |
110 | 110 | |
111 | 111 | $strings = array( |
112 | - 'save' => __('Save','lasso'), |
|
113 | - 'selectText' => __('Please Select Text First.','lasso'), |
|
114 | - 'cancel' => __('Cancel','lasso'), |
|
115 | - 'exiteditor' => __('Exit Editor','lasso'), |
|
116 | - 'saving' => __('Saving...','lasso'), |
|
117 | - 'saved' => __('Saved!','lasso'), |
|
118 | - 'adding' => __('Adding...','lasso'), |
|
119 | - 'added' => __('Added!','lasso'), |
|
120 | - 'loading' => __('Loading...','lasso'), |
|
121 | - 'loadMore' => __('Load More','lasso'), |
|
122 | - 'close' => __('Close','lasso'), |
|
123 | - 'noPostsFound' => __('No more posts found','lasso'), |
|
124 | - 'fetchFail' => __('Fetching failed.','lasso'), |
|
125 | - 'galleryCreated' => __('Gallery Created!','lasso'), |
|
126 | - 'galleryUpdated' => __('Gallery Updated!','lasso'), |
|
127 | - 'justWrite' => __('Just write...','lasso'), |
|
128 | - 'chooseImage' => __('Choose an image','lasso'), |
|
129 | - 'updateImage' => __('Update Image','lasso'), |
|
130 | - 'insertImage' => __('Insert Image','lasso'), |
|
131 | - 'selectImage' => __('Select Image','lasso'), |
|
132 | - 'removeFeatImg' => __('Remove featured image?','lasso'), |
|
133 | - 'updateSelectedImg' => __('Update Selected Image','lasso'), |
|
134 | - 'chooseImages' => __('Choose images','lasso'), |
|
135 | - 'editImage' => __('Edit Image','lasso'), |
|
136 | - 'addImages' => __('Add Images','lasso'), |
|
137 | - 'addNewGallery' => __('Add New Gallery','lasso'), |
|
138 | - 'selectGallery' => __('Select Editus Gallery Image','lasso'), |
|
139 | - 'useSelectedImages' => __('Use Selected Images','lasso'), |
|
140 | - 'publishPost' => __('Publish Post?','lasso'), |
|
141 | - 'publishYes' => __('Yes, publish it!','lasso'), |
|
142 | - 'deletePost' => __('Trash Post?','lasso'), |
|
143 | - 'deleteYes' => __('Yes, trash it!','lasso'), |
|
144 | - 'warning' => __('Oh snap!','laso'), |
|
145 | - 'cancelText' => __('O.K. got it!','lasso'), |
|
146 | - 'missingClass' => __('It looks like we are either missing the Article CSS class, or it is configured incorrectly. Editus will not function correctly without this CSS class.','lasso'), |
|
112 | + 'save' => __('Save', 'lasso'), |
|
113 | + 'selectText' => __('Please Select Text First.', 'lasso'), |
|
114 | + 'cancel' => __('Cancel', 'lasso'), |
|
115 | + 'exiteditor' => __('Exit Editor', 'lasso'), |
|
116 | + 'saving' => __('Saving...', 'lasso'), |
|
117 | + 'saved' => __('Saved!', 'lasso'), |
|
118 | + 'adding' => __('Adding...', 'lasso'), |
|
119 | + 'added' => __('Added!', 'lasso'), |
|
120 | + 'loading' => __('Loading...', 'lasso'), |
|
121 | + 'loadMore' => __('Load More', 'lasso'), |
|
122 | + 'close' => __('Close', 'lasso'), |
|
123 | + 'noPostsFound' => __('No more posts found', 'lasso'), |
|
124 | + 'fetchFail' => __('Fetching failed.', 'lasso'), |
|
125 | + 'galleryCreated' => __('Gallery Created!', 'lasso'), |
|
126 | + 'galleryUpdated' => __('Gallery Updated!', 'lasso'), |
|
127 | + 'justWrite' => __('Just write...', 'lasso'), |
|
128 | + 'chooseImage' => __('Choose an image', 'lasso'), |
|
129 | + 'updateImage' => __('Update Image', 'lasso'), |
|
130 | + 'insertImage' => __('Insert Image', 'lasso'), |
|
131 | + 'selectImage' => __('Select Image', 'lasso'), |
|
132 | + 'removeFeatImg' => __('Remove featured image?', 'lasso'), |
|
133 | + 'updateSelectedImg' => __('Update Selected Image', 'lasso'), |
|
134 | + 'chooseImages' => __('Choose images', 'lasso'), |
|
135 | + 'editImage' => __('Edit Image', 'lasso'), |
|
136 | + 'addImages' => __('Add Images', 'lasso'), |
|
137 | + 'addNewGallery' => __('Add New Gallery', 'lasso'), |
|
138 | + 'selectGallery' => __('Select Editus Gallery Image', 'lasso'), |
|
139 | + 'useSelectedImages' => __('Use Selected Images', 'lasso'), |
|
140 | + 'publishPost' => __('Publish Post?', 'lasso'), |
|
141 | + 'publishYes' => __('Yes, publish it!', 'lasso'), |
|
142 | + 'deletePost' => __('Trash Post?', 'lasso'), |
|
143 | + 'deleteYes' => __('Yes, trash it!', 'lasso'), |
|
144 | + 'warning' => __('Oh snap!', 'laso'), |
|
145 | + 'cancelText' => __('O.K. got it!', 'lasso'), |
|
146 | + 'missingClass' => __('It looks like we are either missing the Article CSS class, or it is configured incorrectly. Editus will not function correctly without this CSS class.', 'lasso'), |
|
147 | 147 | 'missingConfirm' => __('Update Settings', 'lasso'), |
148 | - 'helperText' => __('one more letter','lasso'), |
|
148 | + 'helperText' => __('one more letter', 'lasso'), |
|
149 | 149 | 'editingBackup' => __('You are currently editing a backup copy of this post.'), |
150 | 150 | |
151 | 151 | |
152 | 152 | ); |
153 | 153 | |
154 | - $api_url = trailingslashit( home_url() ) . 'lasso-internal-api'; |
|
154 | + $api_url = trailingslashit(home_url()).'lasso-internal-api'; |
|
155 | 155 | |
156 | 156 | $gallery_class = new gallery(); |
157 | 157 | $gallery_nonce_action = $gallery_class->nonce_action; |
158 | - $gallery_nonce = wp_create_nonce( $gallery_nonce_action ); |
|
158 | + $gallery_nonce = wp_create_nonce($gallery_nonce_action); |
|
159 | 159 | |
160 | 160 | |
161 | 161 | if ($allow_change_date) { |
@@ -170,13 +170,13 @@ discard block |
||
170 | 170 | |
171 | 171 | if (function_exists('rest_url')) { |
172 | 172 | //$rest_root = esc_url_raw( rest_url()); |
173 | - $rest_nonce = wp_create_nonce( 'wp_rest' ); |
|
174 | - $settings = array( 'root' => $rest_root, 'nonce' => $rest_nonce ); |
|
175 | - wp_enqueue_script( 'wp-api', '', array( 'jquery', 'underscore', 'backbone' ), LASSO_VERSION, true ); |
|
176 | - wp_localize_script( 'wp-api', 'wpApiSettings', $settings ); |
|
177 | - wp_localize_script( 'wp-api', 'WP_API_Settings', $settings ); |
|
173 | + $rest_nonce = wp_create_nonce('wp_rest'); |
|
174 | + $settings = array('root' => $rest_root, 'nonce' => $rest_nonce); |
|
175 | + wp_enqueue_script('wp-api', '', array('jquery', 'underscore', 'backbone'), LASSO_VERSION, true); |
|
176 | + wp_localize_script('wp-api', 'wpApiSettings', $settings); |
|
177 | + wp_localize_script('wp-api', 'WP_API_Settings', $settings); |
|
178 | 178 | |
179 | - if ( class_exists( 'WP_REST_Controller' )) { |
|
179 | + if (class_exists('WP_REST_Controller')) { |
|
180 | 180 | // we are using REST API V2 |
181 | 181 | $using_restapiv2 = true; |
182 | 182 | } |
@@ -184,8 +184,8 @@ discard block |
||
184 | 184 | |
185 | 185 | // localized objects |
186 | 186 | $objects = array( |
187 | - 'ajaxurl' => esc_url( $api_url ), |
|
188 | - 'ajaxurl2' => esc_url( admin_url( 'admin-ajax.php' )), |
|
187 | + 'ajaxurl' => esc_url($api_url), |
|
188 | + 'ajaxurl2' => esc_url(admin_url('admin-ajax.php')), |
|
189 | 189 | 'rest_root' => $rest_root, |
190 | 190 | 'rest_nonce' => $rest_nonce, |
191 | 191 | 'editor' => 'lasso--content', // ID of editable content (without #) DONT CHANGE |
@@ -193,13 +193,13 @@ discard block |
||
193 | 193 | 'featImgClass' => $featImgClass, |
194 | 194 | 'titleClass' => $titleClass, |
195 | 195 | 'strings' => $strings, |
196 | - 'settingsLink' => function_exists('is_multisite') && is_multisite() ? network_admin_url( 'settings.php?page=lasso-editor' ) : admin_url( 'admin.php?page=lasso-editor-settings' ), |
|
197 | - 'post_status' => get_post_status( $postid ), |
|
196 | + 'settingsLink' => function_exists('is_multisite') && is_multisite() ? network_admin_url('settings.php?page=lasso-editor') : admin_url('admin.php?page=lasso-editor-settings'), |
|
197 | + 'post_status' => get_post_status($postid), |
|
198 | 198 | 'postid' => $postid, |
199 | 199 | 'permalink' => $permalink, |
200 | 200 | 'edit_others_pages' => current_user_can('edit_others_pages') ? true : false, |
201 | 201 | 'edit_others_posts' => current_user_can('edit_others_posts') ? true : false, |
202 | - 'userCanEdit' => current_user_can('edit_post', $postid ), |
|
202 | + 'userCanEdit' => current_user_can('edit_post', $postid), |
|
203 | 203 | 'can_publish' => is_page() ? current_user_can('publish_pages') : current_user_can('publish_posts'), |
204 | 204 | //'can_publish_posts' => current_user_can('publish_posts'), |
205 | 205 | //'can_publish_pages' => current_user_can('publish_pages'), |
@@ -235,27 +235,27 @@ discard block |
||
235 | 235 | 'postTags' => lasso_get_objects('tag'), |
236 | 236 | 'noResultsDiv' => lasso_editor_empty_results(), |
237 | 237 | 'noRevisionsDiv' => lasso_editor_empty_results('revision'), |
238 | - 'mapTileProvider' => function_exists('aesop_map_tile_provider') ? aesop_map_tile_provider( $postid ) : false, |
|
239 | - 'mapLocations' => get_post_meta( $postid, 'ase_map_component_locations' ), |
|
240 | - 'mapStart' => get_post_meta( $postid, 'ase_map_component_start_point', true ), |
|
241 | - 'mapZoom' => get_post_meta( $postid, 'ase_map_component_zoom', true ), |
|
238 | + 'mapTileProvider' => function_exists('aesop_map_tile_provider') ? aesop_map_tile_provider($postid) : false, |
|
239 | + 'mapLocations' => get_post_meta($postid, 'ase_map_component_locations'), |
|
240 | + 'mapStart' => get_post_meta($postid, 'ase_map_component_start_point', true), |
|
241 | + 'mapZoom' => get_post_meta($postid, 'ase_map_component_zoom', true), |
|
242 | 242 | 'revisionModal' => lasso_editor_revision_modal(), |
243 | 243 | 'isMobile' => wp_is_mobile(), |
244 | - 'enableAutoSave' => lasso_editor_get_option( 'enable_autosave', 'lasso_editor' ), |
|
244 | + 'enableAutoSave' => lasso_editor_get_option('enable_autosave', 'lasso_editor'), |
|
245 | 245 | 'showColor' => $show_color, |
246 | 246 | 'showAlignment' => $show_align, |
247 | 247 | 'showIgnoredItems' => lasso_editor_get_option('show_ignored_items', 'lasso_editor'), |
248 | 248 | 'restapi2' => $using_restapiv2, |
249 | 249 | 'saveusingrest' => $using_restapiv2 && !$disableRESTSave, |
250 | - 'newObjectContent' => '<p>'.apply_filters( 'lasso_new_object_content', __( 'Once upon a time...','lasso') ).'</p>', |
|
250 | + 'newObjectContent' => '<p>'.apply_filters('lasso_new_object_content', __('Once upon a time...', 'lasso')).'</p>', |
|
251 | 251 | 'disableSavePost' => $save_to_post_disabled, |
252 | 252 | 'boldTag' => $bold_tag, |
253 | 253 | 'iTag' => $i_tag, |
254 | 254 | 'customFields' => $custom_fields, |
255 | - 'clickToInsert' => ($insert_comp_ui =='click'), |
|
256 | - 'buttonOnEmptyP' => ($insert_comp_ui =='mediumcom'), // auto show a button to insert components on an empty paragraph |
|
255 | + 'clickToInsert' => ($insert_comp_ui == 'click'), |
|
256 | + 'buttonOnEmptyP' => ($insert_comp_ui == 'mediumcom'), // auto show a button to insert components on an empty paragraph |
|
257 | 257 | 'rtl' => is_rtl(), |
258 | - 'skipToEdit' =>( $delta < 10 && $delta >=0 ), // if it's a new post, skip to edit mode |
|
258 | + 'skipToEdit' =>($delta < 10 && $delta >= 0), // if it's a new post, skip to edit mode |
|
259 | 259 | ); |
260 | 260 | |
261 | 261 | |
@@ -264,9 +264,9 @@ discard block |
||
264 | 264 | |
265 | 265 | if (!$using_restapiv2) { |
266 | 266 | // enqueue REST API V1 |
267 | - wp_enqueue_script( 'wp-api-js', LASSO_URL.'/public/assets/js/source/util--wp-api.js', array( 'jquery', 'underscore', 'backbone' ), LASSO_VERSION, true ); |
|
268 | - $settings = array( 'root' => home_url( $home_url ), 'nonce' => wp_create_nonce( 'wp_json' ) ); |
|
269 | - wp_localize_script( 'wp-api-js', 'WP_API_Settings', $settings ); |
|
267 | + wp_enqueue_script('wp-api-js', LASSO_URL.'/public/assets/js/source/util--wp-api.js', array('jquery', 'underscore', 'backbone'), LASSO_VERSION, true); |
|
268 | + $settings = array('root' => home_url($home_url), 'nonce' => wp_create_nonce('wp_json')); |
|
269 | + wp_localize_script('wp-api-js', 'WP_API_Settings', $settings); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | if ($allow_change_date) { |
@@ -275,13 +275,13 @@ discard block |
||
275 | 275 | wp_enqueue_style('jquery-ui'); |
276 | 276 | } |
277 | 277 | |
278 | - $postfix = ( defined( 'SCRIPT_DEBUG' ) && true === SCRIPT_DEBUG ) ? '' : '.min'; |
|
278 | + $postfix = (defined('SCRIPT_DEBUG') && true === SCRIPT_DEBUG) ? '' : '.min'; |
|
279 | 279 | if ($show_color) { |
280 | - wp_enqueue_script('lasso', LASSO_URL. "/public/assets/js/lasso{$postfix}.js", array('jquery', 'wp-api','iris'), LASSO_VERSION, true); |
|
280 | + wp_enqueue_script('lasso', LASSO_URL."/public/assets/js/lasso{$postfix}.js", array('jquery', 'wp-api', 'iris'), LASSO_VERSION, true); |
|
281 | 281 | } else { |
282 | - wp_enqueue_script('lasso', LASSO_URL. "/public/assets/js/lasso{$postfix}.js", array('jquery', 'wp-api'), LASSO_VERSION, true); |
|
282 | + wp_enqueue_script('lasso', LASSO_URL."/public/assets/js/lasso{$postfix}.js", array('jquery', 'wp-api'), LASSO_VERSION, true); |
|
283 | 283 | } |
284 | - wp_localize_script('lasso', 'lasso_editor', apply_filters('lasso_localized_objects', $objects ) ); |
|
284 | + wp_localize_script('lasso', 'lasso_editor', apply_filters('lasso_localized_objects', $objects)); |
|
285 | 285 | |
286 | 286 | |
287 | 287 | } |
@@ -52,28 +52,28 @@ discard block |
||
52 | 52 | * @param string $method The name of the callback method. |
53 | 53 | |
54 | 54 | */ |
55 | - public function __construct( $action, $callback_class) { |
|
56 | - if ( ! is_object( $callback_class ) ) { |
|
55 | + public function __construct($action, $callback_class) { |
|
56 | + if (!is_object($callback_class)) { |
|
57 | 57 | $this->callback_instance = new $callback_class; |
58 | - }else{ |
|
58 | + } else { |
|
59 | 59 | $this->callback_instance = $callback_class; |
60 | 60 | } |
61 | 61 | |
62 | - if ( $this->check_nonce() ) { |
|
63 | - if ( is_object( $this->callback_instance ) && $this->if_implements() ) { |
|
64 | - if ( $this->other_auth_checks( $action ) ) { |
|
62 | + if ($this->check_nonce()) { |
|
63 | + if (is_object($this->callback_instance) && $this->if_implements()) { |
|
64 | + if ($this->other_auth_checks($action)) { |
|
65 | 65 | $this->status_code = 200; |
66 | 66 | } else { |
67 | - $this->error_message = __( 'Unauthorized action', 'lasso' ); |
|
67 | + $this->error_message = __('Unauthorized action', 'lasso'); |
|
68 | 68 | $this->status_code = 401; |
69 | 69 | } |
70 | 70 | } else { |
71 | - $this->error_message = __( 'All callback classes used for processing the Editus Internal API must implement the lasso\internal_api\api_action interface.', 'lasso' ); |
|
71 | + $this->error_message = __('All callback classes used for processing the Editus Internal API must implement the lasso\internal_api\api_action interface.', 'lasso'); |
|
72 | 72 | $this->status_code = 401; |
73 | 73 | } |
74 | 74 | } else { |
75 | 75 | $this->status_code = 401; |
76 | - $this->error_message = __( 'Nonce invalid', 'lasso' ); |
|
76 | + $this->error_message = __('Nonce invalid', 'lasso'); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | } |
@@ -89,20 +89,20 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return bool True if auth checks were all postive. |
91 | 91 | */ |
92 | - protected function other_auth_checks( $action ) { |
|
92 | + protected function other_auth_checks($action) { |
|
93 | 93 | $auth_callbacks = $this->callback_instance->auth_callbacks(); |
94 | 94 | |
95 | - if ( is_array( $auth_callbacks ) && isset( $auth_callbacks[ $action ] ) && is_array( $auth_callbacks[ $action ] ) ) { |
|
96 | - $checks = $auth_callbacks[ $action ]; |
|
97 | - if ( is_array( $checks ) ) { |
|
98 | - foreach ( $checks as $check ) { |
|
99 | - if ( is_array( $check ) ) { |
|
100 | - $check = call_user_func( array( $check[0], $check[1] ) ); |
|
95 | + if (is_array($auth_callbacks) && isset($auth_callbacks[$action]) && is_array($auth_callbacks[$action])) { |
|
96 | + $checks = $auth_callbacks[$action]; |
|
97 | + if (is_array($checks)) { |
|
98 | + foreach ($checks as $check) { |
|
99 | + if (is_array($check)) { |
|
100 | + $check = call_user_func(array($check[0], $check[1])); |
|
101 | 101 | } else { |
102 | - $check = call_user_func( $check ); |
|
102 | + $check = call_user_func($check); |
|
103 | 103 | } |
104 | 104 | |
105 | - if ( false === $check ) { |
|
105 | + if (false === $check) { |
|
106 | 106 | return false; |
107 | 107 | |
108 | 108 | } |
@@ -127,8 +127,8 @@ discard block |
||
127 | 127 | */ |
128 | 128 | protected function if_implements() { |
129 | 129 | |
130 | - $implements = class_implements( $this->callback_instance ); |
|
131 | - if ( is_array( $implements ) && in_array( 'lasso\internal_api\api_action', $implements ) ) { |
|
130 | + $implements = class_implements($this->callback_instance); |
|
131 | + if (is_array($implements) && in_array('lasso\internal_api\api_action', $implements)) { |
|
132 | 132 | return true; |
133 | 133 | |
134 | 134 | } |
@@ -147,13 +147,13 @@ discard block |
||
147 | 147 | * @return bool |
148 | 148 | */ |
149 | 149 | protected function check_nonce() { |
150 | - if ( isset( $this->callback_instance->nonce_action ) ) { |
|
150 | + if (isset($this->callback_instance->nonce_action)) { |
|
151 | 151 | $nonce = $this->callback_instance->nonce_action; |
152 | - }else{ |
|
152 | + } else { |
|
153 | 153 | $nonce = 'lasso_editor'; |
154 | 154 | } |
155 | 155 | |
156 | - return wp_verify_nonce( $_POST[ 'nonce' ], $nonce ); |
|
156 | + return wp_verify_nonce($_POST['nonce'], $nonce); |
|
157 | 157 | |
158 | 158 | } |
159 | 159 |
@@ -24,35 +24,35 @@ discard block |
||
24 | 24 | global $wp_query; |
25 | 25 | |
26 | 26 | //get action, and if set, possibly act |
27 | - $action = $wp_query->get( 'action' ); |
|
28 | - if ( $action && strpos( $_SERVER['REQUEST_URI'], 'lasso-internal-api' ) ) { |
|
27 | + $action = $wp_query->get('action'); |
|
28 | + if ($action && strpos($_SERVER['REQUEST_URI'], 'lasso-internal-api')) { |
|
29 | 29 | |
30 | - $response = __( 'Editus API Error.', 'lasso' ); |
|
30 | + $response = __('Editus API Error.', 'lasso'); |
|
31 | 31 | $code = 400; |
32 | 32 | |
33 | 33 | //see if have a nonce. Will verify it in auth class. |
34 | - if ( isset( $_POST[ 'nonce' ] ) ) { |
|
34 | + if (isset($_POST['nonce'])) { |
|
35 | 35 | |
36 | - $callback = self::find_callback( strip_tags( $action ) ); |
|
37 | - if ( is_int( $callback ) ) { |
|
36 | + $callback = self::find_callback(strip_tags($action)); |
|
37 | + if (is_int($callback)) { |
|
38 | 38 | $code = $callback; |
39 | - }elseif( ! class_exists( $callback['class'] ) ) { |
|
39 | + }elseif (!class_exists($callback['class'])) { |
|
40 | 40 | $code = 415; |
41 | - }else { |
|
42 | - $action = str_replace( '-', '_', $action ); |
|
41 | + } else { |
|
42 | + $action = str_replace('-', '_', $action); |
|
43 | 43 | $callback_instance = new $callback['class']; |
44 | - $auth = self::auth( $action, $callback_instance, $callback['method'] ); |
|
45 | - if ( 200 == $auth->status_code && is_array( $callback ) ) { |
|
44 | + $auth = self::auth($action, $callback_instance, $callback['method']); |
|
45 | + if (200 == $auth->status_code && is_array($callback)) { |
|
46 | 46 | $code = 200; |
47 | - $data = new find_data( $callback_instance, $action ); |
|
48 | - if ( is_array( $data->data ) && ! empty( $data->data ) ) { |
|
49 | - $response = self::route( $action, $callback_instance, $callback['method'], $data->data ); |
|
47 | + $data = new find_data($callback_instance, $action); |
|
48 | + if (is_array($data->data) && !empty($data->data)) { |
|
49 | + $response = self::route($action, $callback_instance, $callback['method'], $data->data); |
|
50 | 50 | } else { |
51 | 51 | $code = 500; |
52 | 52 | } |
53 | 53 | |
54 | 54 | } else { |
55 | - if ( isset( $auth->error_message ) && is_string( $auth->error_message ) ) { |
|
55 | + if (isset($auth->error_message) && is_string($auth->error_message)) { |
|
56 | 56 | $response = $auth->error_message; |
57 | 57 | } |
58 | 58 | |
@@ -61,12 +61,12 @@ discard block |
||
61 | 61 | |
62 | 62 | } |
63 | 63 | |
64 | - }else{ |
|
64 | + } else { |
|
65 | 65 | $code = 401; |
66 | - $response = __( 'Nonce not set.', 'lasso' ); |
|
66 | + $response = __('Nonce not set.', 'lasso'); |
|
67 | 67 | } |
68 | 68 | |
69 | - self::respond( $response, $code ); |
|
69 | + self::respond($response, $code); |
|
70 | 70 | |
71 | 71 | } |
72 | 72 | |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @return \lasso\internal_api\auth |
87 | 87 | */ |
88 | - protected static function auth( $action, $callback ) { |
|
89 | - return new auth( $action, $callback ); |
|
88 | + protected static function auth($action, $callback) { |
|
89 | + return new auth($action, $callback); |
|
90 | 90 | |
91 | 91 | } |
92 | 92 | |
@@ -99,15 +99,15 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @return array |
101 | 101 | */ |
102 | - protected static function find_callback( $action ) { |
|
103 | - if ( $action ) { |
|
104 | - $parts = explode( '_', $action ); |
|
102 | + protected static function find_callback($action) { |
|
103 | + if ($action) { |
|
104 | + $parts = explode('_', $action); |
|
105 | 105 | |
106 | - if ( isset( $parts[0] ) && isset( $parts[1] ) && isset( $parts[2] ) ) { |
|
107 | - $class = str_replace( '-', '_', $parts[1] ); |
|
106 | + if (isset($parts[0]) && isset($parts[1]) && isset($parts[2])) { |
|
107 | + $class = str_replace('-', '_', $parts[1]); |
|
108 | 108 | |
109 | 109 | $class = "\\lasso\\{$parts[0]}\\{$class}"; |
110 | - $callback = str_replace( '-', '_', $parts[2] ); |
|
110 | + $callback = str_replace('-', '_', $parts[2]); |
|
111 | 111 | |
112 | 112 | return array( |
113 | 113 | 'class' => $class, |
@@ -136,9 +136,9 @@ discard block |
||
136 | 136 | * |
137 | 137 | * @return mixed |
138 | 138 | */ |
139 | - protected static function route( $action, $callback, $method, $data ) { |
|
140 | - if ( method_exists( $callback, $method ) ) { |
|
141 | - $response = call_user_func( array( $callback, $method ), $data ); |
|
139 | + protected static function route($action, $callback, $method, $data) { |
|
140 | + if (method_exists($callback, $method)) { |
|
141 | + $response = call_user_func(array($callback, $method), $data); |
|
142 | 142 | |
143 | 143 | return $response; |
144 | 144 | |
@@ -156,29 +156,29 @@ discard block |
||
156 | 156 | * @param array|string $response The response message to send. |
157 | 157 | * @param bool|int $code Response code or bool. If is bool, response code will be 200 or 401 |
158 | 158 | */ |
159 | - protected static function respond( $response, $code ) { |
|
160 | - if ( true === $code ) { |
|
159 | + protected static function respond($response, $code) { |
|
160 | + if (true === $code) { |
|
161 | 161 | $code = 200; |
162 | 162 | } |
163 | 163 | |
164 | - if ( false == $code ) { |
|
164 | + if (false == $code) { |
|
165 | 165 | $code = 401; |
166 | 166 | } |
167 | 167 | |
168 | - if ( is_string( $response ) ) { |
|
168 | + if (is_string($response)) { |
|
169 | 169 | $data[] = $response; |
170 | - }elseif( is_array( $response ) ) { |
|
170 | + }elseif (is_array($response)) { |
|
171 | 171 | $data = $response; |
172 | - }else{ |
|
172 | + } else { |
|
173 | 173 | $data[] = $code; |
174 | 174 | } |
175 | 175 | |
176 | - status_header( $code ); |
|
176 | + status_header($code); |
|
177 | 177 | nocache_headers(); |
178 | - if ( 200 == $code ) { |
|
179 | - wp_send_json_success( $data ); |
|
180 | - }else{ |
|
181 | - wp_send_json_error( $data ); |
|
178 | + if (200 == $code) { |
|
179 | + wp_send_json_success($data); |
|
180 | + } else { |
|
181 | + wp_send_json_error($data); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | } |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | */ |
201 | 201 | public static function init() { |
202 | 202 | |
203 | - if ( ! self::$instance ) { |
|
203 | + if (!self::$instance) { |
|
204 | 204 | self::$instance = new self; |
205 | 205 | } |
206 | 206 |
@@ -18,27 +18,27 @@ discard block |
||
18 | 18 | */ |
19 | 19 | |
20 | 20 | // If this file is called directly, abort. |
21 | -if ( ! defined( 'WPINC' ) ) { |
|
21 | +if (!defined('WPINC')) { |
|
22 | 22 | die; |
23 | 23 | } |
24 | 24 | |
25 | 25 | // Set some constants |
26 | -define( 'LASSO_VERSION', '1.0.0' ); |
|
27 | -define( 'LASSO_DIR', plugin_dir_path( __FILE__ ) ); |
|
28 | -define( 'LASSO_URL', plugins_url( '', __FILE__ ) ); |
|
29 | -define( 'LASSO_FILE', __FILE__ ); |
|
26 | +define('LASSO_VERSION', '1.0.0'); |
|
27 | +define('LASSO_DIR', plugin_dir_path(__FILE__)); |
|
28 | +define('LASSO_URL', plugins_url('', __FILE__)); |
|
29 | +define('LASSO_FILE', __FILE__); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Load plugin if PHP version is 5.4 or later. |
33 | 33 | */ |
34 | -if ( version_compare( PHP_VERSION, '5.4.0', '>=' ) ) { |
|
34 | +if (version_compare(PHP_VERSION, '5.4.0', '>=')) { |
|
35 | 35 | |
36 | - include_once( LASSO_DIR . '/bootstrap.php' ); |
|
36 | + include_once(LASSO_DIR.'/bootstrap.php'); |
|
37 | 37 | |
38 | 38 | } else { |
39 | 39 | |
40 | 40 | add_action('admin_head', 'lasso_fail_notice'); |
41 | - function lasso_fail_notice(){ |
|
41 | + function lasso_fail_notice() { |
|
42 | 42 | |
43 | 43 | printf('<div class="error"><p>Editus requires PHP 5.4 or higher.</p></div>'); |
44 | 44 | |
@@ -46,11 +46,11 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | add_filter('register_post_type_args', 'lasso_show_in_rest', 10, 2); |
49 | -function lasso_show_in_rest($args, $post_type){ |
|
49 | +function lasso_show_in_rest($args, $post_type) { |
|
50 | 50 | |
51 | - $allowed_post_types = lasso_editor_get_option( 'allowed_post_types', 'lasso_editor', array( ) ); |
|
52 | - $allowed_post_types = apply_filters( 'lasso_allowed_post_types', $allowed_post_types ); |
|
53 | - if (in_array( $post_type,$allowed_post_types)) { |
|
51 | + $allowed_post_types = lasso_editor_get_option('allowed_post_types', 'lasso_editor', array( )); |
|
52 | + $allowed_post_types = apply_filters('lasso_allowed_post_types', $allowed_post_types); |
|
53 | + if (in_array($post_type, $allowed_post_types)) { |
|
54 | 54 | $args['show_in_rest'] = true; |
55 | 55 | if ($post_type != 'post' && $post_type != 'page') { |
56 | 56 | $args['rest_base'] = $post_type; |
@@ -61,21 +61,21 @@ discard block |
||
61 | 61 | } |
62 | 62 | |
63 | 63 | |
64 | -function lasso_editor_get_option( $option, $section, $default = '' ) { |
|
64 | +function lasso_editor_get_option($option, $section, $default = '') { |
|
65 | 65 | |
66 | - if ( empty( $option ) ) |
|
66 | + if (empty($option)) |
|
67 | 67 | return; |
68 | 68 | |
69 | - if ( function_exists( 'is_multisite' ) && is_multisite() ) { |
|
69 | + if (function_exists('is_multisite') && is_multisite()) { |
|
70 | 70 | |
71 | - $options = get_site_option( $section ); |
|
71 | + $options = get_site_option($section); |
|
72 | 72 | |
73 | 73 | } else { |
74 | 74 | |
75 | - $options = get_option( $section ); |
|
75 | + $options = get_option($section); |
|
76 | 76 | } |
77 | 77 | |
78 | - if ( isset( $options[$option] ) ) { |
|
78 | + if (isset($options[$option])) { |
|
79 | 79 | return $options[$option]; |
80 | 80 | } |
81 | 81 |