title = $args['title']; $this->help = $args['help']; $this->slug = $args['slug']; $this->screen = 'fv_player_conversion_' . $this->slug; add_action( 'admin_menu', array( $this, 'admin_page' ) ); add_action( 'wp_ajax_'. $this->screen, array( $this, 'ajax_convert') ); add_action( 'fv_player_conversion_buttons', array( $this, 'conversion_button') ); } function admin_page() { add_submenu_page( 'fv_player', 'FV Player Migration', 'FV Player Migration', 'install_plugins', $this->screen, array($this, 'conversion_screen') ); remove_submenu_page( 'fv_player', $this->screen ); } /** * Count old data * * @return int $count */ function get_count() { global $wpdb; return $wpdb->get_var( "SELECT FOUND_ROWS()" ); } /** * Convert data to new format using ajax * * @return void */ function ajax_convert() { if ( current_user_can( 'install_plugins' ) && check_ajax_referer( $this->screen ) ) { if( function_exists( 'FV_Player_Pro' ) ) { // takes too long to save if not removed remove_filter( 'content_save_pre', array( FV_Player_Pro(), 'save_post' ), 10 ); } $convert_error = false; $offset = intval($_POST['offset']); $offset = 0 + intval($_POST['offset2']) + $offset; $limit = intval($_POST['limit']); $items = $this->get_items( $offset, $limit ); $total = $this->get_count(); // iterate data $result = $this->iterate_data( $items ); $convert_error = $result['convert_error']; $conversions_output = $result['conversions_output']; $percent_done = $total > 0 ? round ( (($offset + $limit) / $total) * 100 ) : 0; $left = $total - ($offset + $limit); // build html output $html = $this->build_output_html( $conversions_output, $percent_done ); // check if we are done if( $percent_done >= 100 ) { // store conversion status $options = get_option( 'fvwpflowplayer' ); if( !isset( $options['conversion'] ) ) { $options['conversion'] = array(); } // store current time as finished time $options['conversion'][$this->slug] = array( 'date' => gmdate('Y-m-d H:i:s'), 'did_cleanup' => false ); update_option( 'fvwpflowplayer', $options ); } // response echo wp_json_encode( array( 'table_rows' => implode( "\n", $html ), 'percent_done' => $percent_done, 'left' => $left, 'total' => $total, 'convert_error' => $convert_error, 'memory_used_peak_mb' => round( memory_get_peak_usage() / 1024 / 1024, 2 ), 'memory_used_mb' => round( memory_get_usage() / 1024 / 1024, 2 ), ) ); } die(); } /** * Create admin page for conversion screen * * @return void */ function conversion_screen() { global $fv_wp_flowplayer_ver; wp_enqueue_script('fv-player-convertor', flowplayer::get_plugin_url().'/js/admin-convertor.js', array('jquery'), filemtime( dirname(__FILE__).'/../../js/admin-convertor.js' ) ); ?>
make_chages_button ): // This checkbox shows the JS confirmation box when clicked to enable ?>