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' ); } try { if ( ! defined( 'MUXVIDEO_PLUGIN_DIR' ) ) { define( 'MUXVIDEO_PLUGIN_DIR', untrailingslashit( dirname( __FILE__ ) ) ); } require_once MUXVIDEO_PLUGIN_DIR . '/includes/includes.php'; } catch (\Throwable $th) { if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { error_log( "Error: defined MUXVIDEO_PLUGIN_DIR" . $th->getMessage() ); } } } 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' ), '1.1.3', 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', 'https://cdn.jsdelivr.net/npm/@mux/mux-player@3.6.0/dist/mux-player.js', array(), '3.6.0', true ); wp_enqueue_script('player'); wp_enqueue_script( 'muxvideo-asset-list-script', plugin_dir_url( __FILE__ ) . '/assets/js/asset-list.js', array( 'jquery' ), '1.1.3', 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() { $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, ]); if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'mux_token_nonce' ) ) { wp_send_json_error( array( 'message' => __( 'Invalid security token. Please refresh and try again.', '2coders-integration-mux-video' ) ) ); } $is_ajax_search = isset( $_POST['is_ajax_search'] ) && $_POST['is_ajax_search'] === '1'; $search = isset( $_POST['search'] ) ? sanitize_text_field($_POST['search']) : ''; $limit = 10; $current_page = isset( $_REQUEST['paged'] ) ? absint( sanitize_text_field( $_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' ); /** * Plugin activation function */ function muxvideo_activate_plugin() { require_once dirname(__FILE__) . '/includes/database.php'; muxvideo_create_captions_table(); } 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['mux_id'])) { wp_send_json_error(['message' => 'No playback IDs provided.']); } $mux_id = json_decode(stripslashes($_POST['mux_id']), true); if (!is_array($mux_id) || empty($mux_id)) { wp_send_json_error(['message' => 'Invalid playback IDs.']); } $placeholders = implode(',', array_fill(0, count($mux_id), '%s')); $table_name = $wpdb->prefix . 'mux_assets'; $table_name = esc_sql($table_name); $mux_id = array_map('sanitize_text_field', $mux_id); $placeholders = implode(',', array_fill(0, count($mux_id), '%s')); $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); $titles = []; foreach ($results as $row) { $titles[$row['mux_id']] = $row['title']; } 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'); } });