API
1 month ago
Blocks
10 months ago
License
1 month ago
AdminNotice.php
3 weeks ago
AdminNotices.php
3 weeks ago
AjaxActions.php
3 weeks ago
Blocks.php
1 year ago
Compatibility.php
10 months ago
Learn.php
1 month ago
Menu.php
1 month ago
Migrations.php
1 year ago
NpsSurvey.php
5 months ago
Onboarding.php
3 weeks ago
Player.php
3 days ago
PluginInstaller.php
1 month ago
PreloadService.php
1 year ago
ProCompatibility.php
1 month ago
ReusableVideos.php
2 weeks ago
RewriteRulesManager.php
1 year ago
Scripts.php
2 weeks ago
Settings.php
1 month ago
Shortcodes.php
1 month ago
Streamer.php
3 weeks ago
Translation.php
3 weeks ago
Usage.php
3 weeks ago
VideoPostType.php
2 weeks ago
AjaxActions.php
59 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Ajax action handlers. |
| 4 | * |
| 5 | * @package PrestoPlayer |
| 6 | */ |
| 7 | |
| 8 | namespace PrestoPlayer\Services; |
| 9 | |
| 10 | use PrestoPlayer\Models\ReusableVideo; |
| 11 | |
| 12 | |
| 13 | /** |
| 14 | * Registers all blocks |
| 15 | */ |
| 16 | class AjaxActions { |
| 17 | |
| 18 | /** |
| 19 | * Register actions |
| 20 | * |
| 21 | * @return void |
| 22 | */ |
| 23 | public function register() { |
| 24 | add_action( 'wp_ajax_presto_fetch_videos', array( $this, 'fetchVideos' ) ); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Fetch videos for dynamic |
| 29 | * |
| 30 | * @return void |
| 31 | */ |
| 32 | public function fetchVideos() { |
| 33 | // Verify nonce. |
| 34 | $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : ''; |
| 35 | if ( ! wp_verify_nonce( $nonce, 'wp_rest' ) ) { |
| 36 | wp_send_json_error(); |
| 37 | } |
| 38 | |
| 39 | // Need to edit posts. |
| 40 | if ( ! current_user_can( 'edit_posts' ) ) { |
| 41 | wp_send_json_error(); |
| 42 | } |
| 43 | |
| 44 | $args = array(); |
| 45 | |
| 46 | if ( ! empty( $_POST['search'] ) ) { |
| 47 | $args['s'] = sanitize_text_field( wp_unslash( $_POST['search'] ) ); |
| 48 | } |
| 49 | |
| 50 | if ( ! empty( $_POST['post_id'] ) ) { |
| 51 | $args['post__in'][0] = absint( wp_unslash( $_POST['post_id'] ) ); // Convert single post_id into array. |
| 52 | } |
| 53 | |
| 54 | $videos = ( new ReusableVideo() )->fetch( $args ); |
| 55 | |
| 56 | wp_send_json_success( $videos ); |
| 57 | } |
| 58 | } |
| 59 |