@@ -8,83 +8,83 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Wordlift_Mapping_Ajax_Adapter { |
| 10 | 10 | |
| 11 | - /** |
|
| 12 | - * The {@link Wordlift_Mapping_Service} instance. |
|
| 13 | - * |
|
| 14 | - * @since 3.20.0 |
|
| 15 | - * @access private |
|
| 16 | - * @var \Wordlift_Mapping_Service $mapping_service The {@link Wordlift_Mapping_Service} instance. |
|
| 17 | - */ |
|
| 18 | - private $mapping_service; |
|
| 11 | + /** |
|
| 12 | + * The {@link Wordlift_Mapping_Service} instance. |
|
| 13 | + * |
|
| 14 | + * @since 3.20.0 |
|
| 15 | + * @access private |
|
| 16 | + * @var \Wordlift_Mapping_Service $mapping_service The {@link Wordlift_Mapping_Service} instance. |
|
| 17 | + */ |
|
| 18 | + private $mapping_service; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Create a {@link Wordlift_Mapping_Ajax_Adapter} instance. |
|
| 22 | - * |
|
| 23 | - * @param Wordlift_Mapping_Service $mapping_service The {@link Wordlift_Mapping_Service} instance. |
|
| 24 | - * |
|
| 25 | - * @since 3.20.0 |
|
| 26 | - */ |
|
| 27 | - public function __construct( $mapping_service ) { |
|
| 20 | + /** |
|
| 21 | + * Create a {@link Wordlift_Mapping_Ajax_Adapter} instance. |
|
| 22 | + * |
|
| 23 | + * @param Wordlift_Mapping_Service $mapping_service The {@link Wordlift_Mapping_Service} instance. |
|
| 24 | + * |
|
| 25 | + * @since 3.20.0 |
|
| 26 | + */ |
|
| 27 | + public function __construct( $mapping_service ) { |
|
| 28 | 28 | |
| 29 | - $this->mapping_service = $mapping_service; |
|
| 29 | + $this->mapping_service = $mapping_service; |
|
| 30 | 30 | |
| 31 | - add_action( 'wp_ajax_wl_set_entity_types_for_post_type', array( $this, 'set_entity_types_for_post_type' ) ); |
|
| 32 | - add_action( 'wp_ajax_wl_update_post_type_entity_types', array( $this, 'update_post_type_entity_types' ) ); |
|
| 31 | + add_action( 'wp_ajax_wl_set_entity_types_for_post_type', array( $this, 'set_entity_types_for_post_type' ) ); |
|
| 32 | + add_action( 'wp_ajax_wl_update_post_type_entity_types', array( $this, 'update_post_type_entity_types' ) ); |
|
| 33 | 33 | |
| 34 | - } |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * |
|
| 38 | - */ |
|
| 39 | - public function set_entity_types_for_post_type() { |
|
| 36 | + /** |
|
| 37 | + * |
|
| 38 | + */ |
|
| 39 | + public function set_entity_types_for_post_type() { |
|
| 40 | 40 | |
| 41 | - if ( ! isset( $_REQUEST['post_type'] ) || ! isset( $_REQUEST['entity_types'] ) ) { |
|
| 42 | - return; |
|
| 43 | - } |
|
| 41 | + if ( ! isset( $_REQUEST['post_type'] ) || ! isset( $_REQUEST['entity_types'] ) ) { |
|
| 42 | + return; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - $post_type = sanitize_text_field( wp_unslash( $_REQUEST['post_type'] ) ); |
|
| 46 | - $entity_types = array_map( 'sanitize_text_field', wp_unslash( (array) $_REQUEST['entity_types'] ) ); |
|
| 45 | + $post_type = sanitize_text_field( wp_unslash( $_REQUEST['post_type'] ) ); |
|
| 46 | + $entity_types = array_map( 'sanitize_text_field', wp_unslash( (array) $_REQUEST['entity_types'] ) ); |
|
| 47 | 47 | |
| 48 | - $this->mapping_service->set_entity_types_for_post_type( $post_type, $entity_types ); |
|
| 48 | + $this->mapping_service->set_entity_types_for_post_type( $post_type, $entity_types ); |
|
| 49 | 49 | |
| 50 | - wp_send_json_success(); |
|
| 50 | + wp_send_json_success(); |
|
| 51 | 51 | |
| 52 | - } |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - public function update_post_type_entity_types() { |
|
| 54 | + public function update_post_type_entity_types() { |
|
| 55 | 55 | |
| 56 | - // If the nonce is invalid, return an error. |
|
| 57 | - $nonce = isset( $_REQUEST['_nonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_nonce'] ) ): ''; |
|
| 58 | - if ( ! wp_verify_nonce( $nonce, 'update_post_type_entity_types' ) ) { |
|
| 59 | - wp_send_json_error( __( 'Nonce Security Check Failed!', 'wordlift' ) ); |
|
| 60 | - } |
|
| 56 | + // If the nonce is invalid, return an error. |
|
| 57 | + $nonce = isset( $_REQUEST['_nonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_nonce'] ) ): ''; |
|
| 58 | + if ( ! wp_verify_nonce( $nonce, 'update_post_type_entity_types' ) ) { |
|
| 59 | + wp_send_json_error( __( 'Nonce Security Check Failed!', 'wordlift' ) ); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - if ( empty( $_REQUEST['post_type'] ) ) { |
|
| 63 | - wp_send_json_error( __( '`post_type` is required', 'wordlift' ) ); |
|
| 64 | - } |
|
| 62 | + if ( empty( $_REQUEST['post_type'] ) ) { |
|
| 63 | + wp_send_json_error( __( '`post_type` is required', 'wordlift' ) ); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - if ( empty( $_REQUEST['entity_types'] ) ) { |
|
| 67 | - wp_send_json_error( __( '`entity_types` is required', 'wordlift' ) ); |
|
| 68 | - } |
|
| 66 | + if ( empty( $_REQUEST['entity_types'] ) ) { |
|
| 67 | + wp_send_json_error( __( '`entity_types` is required', 'wordlift' ) ); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - // Get the post type. |
|
| 71 | - $post_type = isset( $_REQUEST['post_type'] ) ? sanitize_text_field(wp_unslash( $_REQUEST['post_type'] ) ) : ''; |
|
| 70 | + // Get the post type. |
|
| 71 | + $post_type = isset( $_REQUEST['post_type'] ) ? sanitize_text_field(wp_unslash( $_REQUEST['post_type'] ) ) : ''; |
|
| 72 | 72 | |
| 73 | - // Get the entity types URIs. |
|
| 74 | - $entity_types = isset( $_REQUEST['entity_types'] ) ? array_map( 'sanitize_url', wp_unslash( (array) $_REQUEST['entity_types'] ) ) : array(); |
|
| 73 | + // Get the entity types URIs. |
|
| 74 | + $entity_types = isset( $_REQUEST['entity_types'] ) ? array_map( 'sanitize_url', wp_unslash( (array) $_REQUEST['entity_types'] ) ) : array(); |
|
| 75 | 75 | |
| 76 | - // Get the offset. |
|
| 77 | - $offset = isset( $_REQUEST['offset'] ) ? intval( $_REQUEST['offset'] ) : 0; |
|
| 76 | + // Get the offset. |
|
| 77 | + $offset = isset( $_REQUEST['offset'] ) ? intval( $_REQUEST['offset'] ) : 0; |
|
| 78 | 78 | |
| 79 | - // Update and get the results. |
|
| 80 | - $result = $this->mapping_service->update( $post_type, $entity_types, $offset ); |
|
| 79 | + // Update and get the results. |
|
| 80 | + $result = $this->mapping_service->update( $post_type, $entity_types, $offset ); |
|
| 81 | 81 | |
| 82 | - // Add our nonce to the result. |
|
| 83 | - $result['_nonce'] = wp_create_nonce( 'update_post_type_entity_types' ); |
|
| 82 | + // Add our nonce to the result. |
|
| 83 | + $result['_nonce'] = wp_create_nonce( 'update_post_type_entity_types' ); |
|
| 84 | 84 | |
| 85 | - // Finally send the results. |
|
| 86 | - wp_send_json_success( $result ); |
|
| 85 | + // Finally send the results. |
|
| 86 | + wp_send_json_success( $result ); |
|
| 87 | 87 | |
| 88 | - } |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | 90 | } |
@@ -24,12 +24,12 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @since 3.20.0 |
| 26 | 26 | */ |
| 27 | - public function __construct( $mapping_service ) { |
|
| 27 | + public function __construct($mapping_service) { |
|
| 28 | 28 | |
| 29 | 29 | $this->mapping_service = $mapping_service; |
| 30 | 30 | |
| 31 | - add_action( 'wp_ajax_wl_set_entity_types_for_post_type', array( $this, 'set_entity_types_for_post_type' ) ); |
|
| 32 | - add_action( 'wp_ajax_wl_update_post_type_entity_types', array( $this, 'update_post_type_entity_types' ) ); |
|
| 31 | + add_action('wp_ajax_wl_set_entity_types_for_post_type', array($this, 'set_entity_types_for_post_type')); |
|
| 32 | + add_action('wp_ajax_wl_update_post_type_entity_types', array($this, 'update_post_type_entity_types')); |
|
| 33 | 33 | |
| 34 | 34 | } |
| 35 | 35 | |
@@ -38,14 +38,14 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | public function set_entity_types_for_post_type() { |
| 40 | 40 | |
| 41 | - if ( ! isset( $_REQUEST['post_type'] ) || ! isset( $_REQUEST['entity_types'] ) ) { |
|
| 41 | + if ( ! isset($_REQUEST['post_type']) || ! isset($_REQUEST['entity_types'])) { |
|
| 42 | 42 | return; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - $post_type = sanitize_text_field( wp_unslash( $_REQUEST['post_type'] ) ); |
|
| 46 | - $entity_types = array_map( 'sanitize_text_field', wp_unslash( (array) $_REQUEST['entity_types'] ) ); |
|
| 45 | + $post_type = sanitize_text_field(wp_unslash($_REQUEST['post_type'])); |
|
| 46 | + $entity_types = array_map('sanitize_text_field', wp_unslash((array) $_REQUEST['entity_types'])); |
|
| 47 | 47 | |
| 48 | - $this->mapping_service->set_entity_types_for_post_type( $post_type, $entity_types ); |
|
| 48 | + $this->mapping_service->set_entity_types_for_post_type($post_type, $entity_types); |
|
| 49 | 49 | |
| 50 | 50 | wp_send_json_success(); |
| 51 | 51 | |
@@ -54,36 +54,36 @@ discard block |
||
| 54 | 54 | public function update_post_type_entity_types() { |
| 55 | 55 | |
| 56 | 56 | // If the nonce is invalid, return an error. |
| 57 | - $nonce = isset( $_REQUEST['_nonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_nonce'] ) ): ''; |
|
| 58 | - if ( ! wp_verify_nonce( $nonce, 'update_post_type_entity_types' ) ) { |
|
| 59 | - wp_send_json_error( __( 'Nonce Security Check Failed!', 'wordlift' ) ); |
|
| 57 | + $nonce = isset($_REQUEST['_nonce']) ? sanitize_text_field(wp_unslash($_REQUEST['_nonce'])) : ''; |
|
| 58 | + if ( ! wp_verify_nonce($nonce, 'update_post_type_entity_types')) { |
|
| 59 | + wp_send_json_error(__('Nonce Security Check Failed!', 'wordlift')); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - if ( empty( $_REQUEST['post_type'] ) ) { |
|
| 63 | - wp_send_json_error( __( '`post_type` is required', 'wordlift' ) ); |
|
| 62 | + if (empty($_REQUEST['post_type'])) { |
|
| 63 | + wp_send_json_error(__('`post_type` is required', 'wordlift')); |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if ( empty( $_REQUEST['entity_types'] ) ) { |
|
| 67 | - wp_send_json_error( __( '`entity_types` is required', 'wordlift' ) ); |
|
| 66 | + if (empty($_REQUEST['entity_types'])) { |
|
| 67 | + wp_send_json_error(__('`entity_types` is required', 'wordlift')); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | // Get the post type. |
| 71 | - $post_type = isset( $_REQUEST['post_type'] ) ? sanitize_text_field(wp_unslash( $_REQUEST['post_type'] ) ) : ''; |
|
| 71 | + $post_type = isset($_REQUEST['post_type']) ? sanitize_text_field(wp_unslash($_REQUEST['post_type'])) : ''; |
|
| 72 | 72 | |
| 73 | 73 | // Get the entity types URIs. |
| 74 | - $entity_types = isset( $_REQUEST['entity_types'] ) ? array_map( 'sanitize_url', wp_unslash( (array) $_REQUEST['entity_types'] ) ) : array(); |
|
| 74 | + $entity_types = isset($_REQUEST['entity_types']) ? array_map('sanitize_url', wp_unslash((array) $_REQUEST['entity_types'])) : array(); |
|
| 75 | 75 | |
| 76 | 76 | // Get the offset. |
| 77 | - $offset = isset( $_REQUEST['offset'] ) ? intval( $_REQUEST['offset'] ) : 0; |
|
| 77 | + $offset = isset($_REQUEST['offset']) ? intval($_REQUEST['offset']) : 0; |
|
| 78 | 78 | |
| 79 | 79 | // Update and get the results. |
| 80 | - $result = $this->mapping_service->update( $post_type, $entity_types, $offset ); |
|
| 80 | + $result = $this->mapping_service->update($post_type, $entity_types, $offset); |
|
| 81 | 81 | |
| 82 | 82 | // Add our nonce to the result. |
| 83 | - $result['_nonce'] = wp_create_nonce( 'update_post_type_entity_types' ); |
|
| 83 | + $result['_nonce'] = wp_create_nonce('update_post_type_entity_types'); |
|
| 84 | 84 | |
| 85 | 85 | // Finally send the results. |
| 86 | - wp_send_json_success( $result ); |
|
| 86 | + wp_send_json_success($result); |
|
| 87 | 87 | |
| 88 | 88 | } |
| 89 | 89 | |