set_basename( true, __FILE__ ); } else { // DO NOT REMOVE THIS IF, IT IS ESSENTIAL FOR THE `function_exists` CALL ABOVE TO PROPERLY WORK. if ( ! function_exists( 'muxvideo_fs' ) ) { // Create a helper function for easy SDK access. function muxvideo_fs() { global $muxvideo_fs; if ( ! isset( $muxvideo_fs ) ) { // Include Freemius SDK. require_once dirname( __FILE__ ) . '/freemius/start.php'; $muxvideo_fs = fs_dynamic_init( array( 'id' => '12655', 'slug' => 'mux-media', 'type' => 'plugin', 'public_key' => 'pk_8d5a7f9435bdb0602b57080f5b123', 'is_premium' => true, 'premium_suffix' => 'PRO', // If your plugin is a serviceware, set this option to false. 'has_premium_version' => true, 'has_addons' => false, 'has_paid_plans' => true, 'menu' => array( 'slug' => 'muxvideo', 'first-path' => 'admin.php?page=muxvideo-settings', 'contact' => true, 'support' => false, 'pricing' => true, ), // Set the SDK to work in a sandbox mode (for development & testing). // IMPORTANT: MAKE SURE TO REMOVE SECRET KEY BEFORE DEPLOYMENT. //'secret_key' => '', ) ); } // Set license permissions into a variable if ( ! defined( 'MUXVIDEO_FS_CAN_USE_PREMIUM_CODE' ) ) { $muxvideo_fs_can_use_premium_code = $muxvideo_fs->can_use_premium_code(); define( 'MUXVIDEO_FS_CAN_USE_PREMIUM_CODE', $muxvideo_fs_can_use_premium_code ); } return $muxvideo_fs; } // Init Freemius. muxvideo_fs(); // Signal that SDK was initiated. do_action( 'muxvideo_fs_loaded' ); } if ( ! defined( 'MUXVIDEO_PLUGIN_DIR' ) ) { define( 'MUXVIDEO_PLUGIN_DIR', untrailingslashit( dirname( __FILE__ ) ) ); } add_action('plugins_loaded', function() { require_once MUXVIDEO_PLUGIN_DIR . '/includes/includes.php'; }); } function muxvideo_block_editor_assets() { wp_enqueue_script( 'mux-video-gutenberg-block', plugin_dir_url( __FILE__ ) . 'mux-video-gutenberg-block.js', array( 'wp-blocks', 'wp-editor' ), MUXVIDEO_PLUGIN_VERSION, true ); wp_enqueue_style( 'mux-video-gutenberg-block-styles', plugin_dir_url( __FILE__ ) . 'assets/css/admin.css', array( 'wp-edit-blocks' ), filemtime( plugin_dir_path( __FILE__ ) . 'assets/css/admin.css' ) ); wp_localize_script( 'mux-video-gutenberg-block', 'mux_ajax_data', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'mux_token_nonce' ), 'contentUrl' => admin_url('admin-ajax.php'), ) ); wp_localize_script( 'mux-video-gutenberg-block', 'muxPluginData', array( 'assetsUrl' => plugin_dir_url( __FILE__ ) . 'assets/', ) ); } function muxvideo_block_frontend_assets() { wp_register_script( 'player', plugin_dir_url( __FILE__ ) . 'assets/lib/mux-player-2.3.2.min.js', array(), '2.3.2', true ); wp_enqueue_script('player'); wp_enqueue_script( 'muxvideo-asset-list-script', plugin_dir_url( __FILE__ ) . '/assets/js/asset-list.js', array( 'jquery' ), MUXVIDEO_PLUGIN_VERSION, true ); } add_action( 'enqueue_block_editor_assets', 'muxvideo_block_editor_assets' ); add_action( 'enqueue_block_assets', 'muxvideo_block_frontend_assets' ); function muxvideo_get_assets_list() { if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'mux_token_nonce' ) ) { wp_send_json_error( array( 'message' => __( 'Invalid security token. Please refresh and try again.', '2coders-integration-mux-video' ) ) ); return; } if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'message' => __( 'You do not have permission to access this page.', '2coders-integration-mux-video' ) ), 403 ); return; } $nonce = wp_create_nonce( 'mux_token_nonce' ); wp_localize_script( 'mux--admin-functions', 'mux_ajax_data', [ 'ajax_url' => admin_url( 'admin-ajax.php' ), 'nonce' => $nonce, ] ); $is_ajax_search = isset( $_POST['is_ajax_search'] ) && $_POST['is_ajax_search'] === '1'; $search = isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : ''; $limit = 10; $current_page = isset( $_REQUEST['paged'] ) ? absint( wp_unslash( $_REQUEST['paged'] ) ) : 1; $assetsApi = muxvideo_api_client_init(); ob_start(); muxvideo_display_gutenberg_assets_list($search, $current_page, !$is_ajax_search); $content = ob_get_clean(); wp_send_json_success( array( 'content' => $content ) ); wp_die(); } add_action( 'wp_ajax_muxvideo_get_assets_list', 'muxvideo_get_assets_list' ); add_action('wp_ajax_muxvideo_get_mux_asset_titles', 'muxvideo_get_mux_asset_titles_callback'); function muxvideo_get_mux_asset_titles_callback() { global $wpdb; if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce'] ) ), 'mux_token_nonce' ) ) { wp_send_json_error( array( 'message' => __( 'Invalid security token. Please refresh and try again.', '2coders-integration-mux-video' ) ) ); return; } if ( ! current_user_can( 'manage_options' ) ) { wp_send_json_error( array( 'message' => __( 'You do not have permission to access this page.', '2coders-integration-mux-video' ) ), 403 ); return; } if ( ! isset( $_POST['mux_id'] ) ) { wp_send_json_error( [ 'message' => 'No playback IDs provided.' ] ); return; } // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- JSON payload; individual elements are sanitized below. $mux_id = json_decode( wp_unslash( $_POST['mux_id'] ), true ); if (!is_array($mux_id) || empty($mux_id)) { wp_send_json_error(['message' => 'Invalid playback IDs.']); } $mux_id = array_map('sanitize_text_field', $mux_id); $placeholders = implode( ',', array_fill( 0, count( $mux_id ), '%s' ) ); // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnfinishedPrepare, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- $placeholders is built from a fixed %s literal, real values are passed to prepare() via the variadic spread below. $query = $wpdb->prepare( "SELECT mux_id, title FROM {$wpdb->prefix}mux_assets WHERE mux_id IN ($placeholders) LIMIT 100", ...$mux_id ); $results = $wpdb->get_results( $query, ARRAY_A ); // phpcs:enable $titles = wp_list_pluck($results, 'title', 'mux_id'); wp_send_json_success($titles); } add_action('send_headers', function() { if ( ! is_admin() ) { return; } $screen = get_current_screen(); if ( $screen && strpos( $screen->id, 'muxvideo' ) !== false ) { header('X-Content-Type-Options: nosniff'); header('X-Frame-Options: SAMEORIGIN'); header('X-XSS-Protection: 1; mode=block'); } });