__( 'You are not allowed to do this.', 'developersd-logo-slider' ) ), 403 ); } check_ajax_referer( DeveloperSD_LS_Security::NONCE_ACTION_AJAX, 'nonce' ); $post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0; // Keep each JSON container intact until decoding; the decoded values are // immediately sanitized against the plugin's strict schemas below. $logos_raw = isset( $_POST['logos'] ) ? wp_unslash( $_POST['logos'] ) : '[]'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized field-by-field immediately after json_decode(). $settings_raw = isset( $_POST['settings'] ) ? wp_unslash( $_POST['settings'] ) : '{}'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Sanitized against the settings schema immediately after json_decode(). $logos = json_decode( $logos_raw, true ); $settings = json_decode( $settings_raw, true ); $logos = DeveloperSD_LS_Security::sanitize_logos( is_array( $logos ) ? $logos : array() ); $settings = DeveloperSD_LS_Security::sanitize_settings( is_array( $settings ) ? $settings : array(), DeveloperSD_LS_Slider::default_settings() ); $html = DeveloperSD_LS_Frontend::render_from_data( $post_id, $logos, $settings ); if ( '' === $html ) { $html = '

' . esc_html__( 'Add at least one logo to see a preview.', 'developersd-logo-slider' ) . '

'; } wp_send_json_success( array( 'html' => $html ) ); } /** * Toggle a slider between Active and Inactive from the list table. */ public function handle_toggle_status() { if ( ! DeveloperSD_LS_Security::current_user_can_manage() ) { wp_send_json_error( array( 'message' => __( 'You are not allowed to do this.', 'developersd-logo-slider' ) ), 403 ); } check_ajax_referer( DeveloperSD_LS_Security::NONCE_ACTION_AJAX, 'nonce' ); $post_id = isset( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0; if ( ! $post_id || DeveloperSD_LS_Post_Type::POST_TYPE !== get_post_type( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) { wp_send_json_error( array( 'message' => __( 'Invalid slider.', 'developersd-logo-slider' ) ), 400 ); } $slider = new DeveloperSD_LS_Slider( $post_id ); $new_status = $slider->is_active() ? 'inactive' : 'active'; $slider->set_status( $new_status ); wp_send_json_success( array( 'status' => $new_status, 'label' => 'active' === $new_status ? __( 'Active', 'developersd-logo-slider' ) : __( 'Inactive', 'developersd-logo-slider' ), ) ); } } new DeveloperSD_LS_Ajax();