BPMediaImporter::table_exists PHP Method

table_exists() static public method

static public table_exists ( $table )
    static function table_exists($table)
    {
        global $wpdb;
        if (1 === intval($wpdb->query($wpdb->prepare('SHOW TABLES LIKE %s', $table)))) {
            // @codingStandardsIgnoreLine
            return true;
        }
        return false;
    }

Usage Example

 function ui()
 {
     global $wpdb;
     $bp_album_active = BPMediaImporter::_active('bp-album/loader.php');
     $table = "{$wpdb->base_prefix}bp_album";
     if (BPMediaImporter::table_exists($table)) {
         $this->progress = new rtProgress();
         $total = BPMediaAlbumimporter::get_total_count();
         //            print_r($total);
         $remaining_comments = $this->get_remaining_comments();
         //            print_r($remaining_comments);
         $finished = BPMediaAlbumimporter::get_completed_media($total);
         //            print_r($finished);
         $finished_users = BPMediaAlbumimporter::get_completed_users();
         //            print_R($finished_users);
         $finished_comments = $this->get_finished_comments();
         //            print_r($finished_comments);
         $total_comments = (int) $finished_comments + (int) $remaining_comments;
         //            print_r($total_comments);
         $completed_users_favorites = (int) get_site_option('bp_media_bp_album_favorite_import_status', 0);
         //            print_r($completed_users_favorites);
         $users = count_users();
         //            print_r($users);
         echo '<div id="bpmedia-bpalbumimporter">';
         if ($finished[0]->media != $total[0]->media || $users['total_users'] > $completed_users_favorites) {
             if (1 != $bp_album_active) {
                 echo '<div id="setting-error-bp-album-importer" class="error settings-error below-h2">
                     <p><strong>' . __('Warning!', 'rtmedia') . '</strong> ' . sprintf(__('This import process is irreversible. Although everything is tested, please take a <a target="_blank" href="http://codex.wordpress.org/WordPress_Backups">backup of your database and files</a>, before proceeding. If you don\'t know your way around databases and files, consider <a target="_blank" href="%s">hiring us</a>, or another professional.', 'rtmedia'), 'http://rtcamp.com/contact/?purpose=buddypress&utm_source=dashboard&utm_medium=plugin&utm_campaign=buddypress-media') . '</p>';
                 echo '<p>' . __('If you have set "WP_DEBUG" in you wp-config.php file, please make sure it is set to "false", so that it doesn\'t conflict with the import process.', 'rtmedia') . '</p></div>';
                 echo '<div class="bp-album-import-accept"><p><strong><label for="bp-album-import-accept"><input type="checkbox" value="accept" name="bp-album-import-accept" id="bp-album-import-accept" /> ' . __('I have taken a backup of the database and files of this site.', 'rtmedia') . '</label></strong></p></div>';
                 echo '<button id="bpmedia-bpalbumimport" class="button button-primary">';
                 _e('Start Import', 'rtmedia');
                 echo '</button>';
                 echo '<div class="bp-album-importer-wizard">';
                 echo '<div class="bp-album-users">';
                 echo '<strong>';
                 echo __('Users', 'rtmedia') . ': <span class="finished">' . $finished_users[0]->users . '</span> / <span class="total">' . $total[0]->users . '</span>';
                 echo '</strong>';
                 if (0 != $total[0]->users) {
                     $users_progress = $this->progress->progress($finished_users[0]->users, $total[0]->users);
                     $this->progress->progress_ui($users_progress);
                 }
                 echo '</div>';
                 echo '<br />';
                 echo '<div class="bp-album-media">';
                 echo '<strong>';
                 echo __('Media', 'rtmedia') . ': <span class="finished">' . $finished[0]->media . '</span> / <span class="total">' . $total[0]->media . '</span>';
                 echo '</strong>';
                 $progress = 100;
                 if (0 != $total[0]->media) {
                     $todo = $total[0]->media - $finished[0]->media;
                     $steps = ceil($todo / 5);
                     $laststep = $todo % 5;
                     $progress = $this->progress->progress($finished[0]->media, $total[0]->media);
                     echo '<input type="hidden" value="' . $finished[0]->media . '" name="finished"/>';
                     echo '<input type="hidden" value="' . $total[0]->media . '" name="total"/>';
                     echo '<input type="hidden" value="' . $todo . '" name="todo"/>';
                     echo '<input type="hidden" value="' . $steps . '" name="steps"/>';
                     echo '<input type="hidden" value="' . $laststep . '" name="laststep"/>';
                     $this->progress->progress_ui($progress);
                 }
                 echo '</div>';
                 echo '<br>';
                 echo '<div class="bp-album-comments">';
                 if (0 != $total_comments) {
                     echo '<strong>';
                     echo __('Comments', 'rtmedia') . ': <span class="finished">' . $finished_comments . '</span> / <span class="total">' . $total_comments . '</span>';
                     echo '</strong>';
                     $comments_progress = $this->progress->progress($finished_comments, $total_comments);
                     $this->progress->progress_ui($comments_progress);
                     echo '<br />';
                 } else {
                     echo '<p><strong>' . __('Comments: 0/0 (No comments to import)', 'rtmedia') . '</strong></p>';
                 }
                 echo '</div>';
                 if (0 != $completed_users_favorites) {
                     echo '<br />';
                     echo '<div class="bp-album-favorites">';
                     echo '<strong>';
                     echo __('User\'s Favorites', 'rtmedia') . ': <span class="finished">' . $completed_users_favorites . '</span> / <span class="total">' . $users['total_users'] . '</span>';
                     echo '</strong>';
                     $favorites_progress = $this->progress->progress($completed_users_favorites, $users['total_users']);
                     $this->progress->progress_ui($favorites_progress);
                     echo '</div>';
                 }
                 echo '</div>';
             } else {
                 $deactivate_link = wp_nonce_url(admin_url('plugins.php?action=deactivate&amp;plugin=' . urlencode($this->path)), 'deactivate-plugin_' . $this->path);
                 echo '<p>' . __('BP-Album is active on your site and will cause problems with the import.', 'rtmedia') . '</p>';
                 echo '<p><a class="button button-primary deactivate-bp-album" href="' . $deactivate_link . '">' . __('Click here to deactivate BP-Album and continue importing', 'rtmedia') . '</a></p>';
             }
         } else {
             $corrupt_media = BPMediaAlbumimporter::get_corrupt_media();
             if ($corrupt_media) {
                 echo '<div class="error below-h2">';
                 echo '<p><strong>' . __('Some of the media failed to import. The file might be corrupt or deleted.', 'rtmedia') . '</strong></p>';
                 echo '<p>' . sprintf(__('The following %d BP Album Media id\'s could not be imported', 'rtmedia'), count($corrupt_media)) . ': </p>';
                 $corrupt_prefix_path = str_replace('/wp-content', '', WP_CONTENT_URL);
                 foreach ($corrupt_media as $corrupt) {
                     echo '<p>' . $corrupt->id . ' => <a href="' . $corrupt_prefix_path . $corrupt->pic_org_url . '">' . $corrupt->title . '</a></p>';
                 }
                 echo '</div>';
             } else {
                 echo '<div class="bp-album-import-accept i-accept">';
                 echo '<p class="info">';
                 $message = sprintf(__('I just imported bp-album to @rtMediaWP http://rt.cx/rtmedia on %s', 'rtmedia'), home_url());
                 echo '<strong>' . __('Congratulations!', 'rtmedia') . '</strong> ' . __('All media from BP Album has been imported.', 'rtmedia');
                 echo ' <a href="http://twitter.com/home/?status=' . $message . '" class="button button-import-tweet" target= "_blank">' . __('Tweet this', 'rtmedia') . '</a>';
                 echo '</p>';
                 echo '</div>';
             }
             echo '<p>' . __('However, a lot of unnecessary files and a database table are still eating up your resources. If everything seems fine, you can clean this data up.', 'rtmedia') . '</p>';
             echo '<br />';
             echo '<button id="bpmedia-bpalbumimport-cleanup" class="button btn-warning">';
             _e('Clean up Now', 'rtmedia');
             echo '</button>';
             echo ' <a href="' . esc_url(add_query_arg(array('page' => 'bp-media-settings'), is_multisite() ? network_admin_url('admin.php') : admin_url('admin.php'))) . '" id="bpmedia-bpalbumimport-cleanup-later" class="button">';
             _e('Clean up Later', 'rtmedia');
             echo '</a>';
             echo '<br />';
             echo '<br />';
             echo '<br />';
             echo '<strong>' . __('Why don\'t you try adding some instagram like effects to your images?', 'rtmedia') . '</strong>';
             echo '<div class="bp-media-addon">
             <a href="http://rtcamp.com/products/buddypress-media-instagram/?utm_source=dashboard&amp;utm_medium=plugin&amp;utm_campaign=buddypress-media&amp;utm_content=bp-album-importer" title="BuddyPress-Media Instagram" target="_blank">
                 <img width="240" height="184" title="BuddyPress-Media Instagram" alt="BuddyPress-Media Instagram" src="' . $img_src . 'BuddyPressMedia-Instagram.png?ref=bp-album-importer">
             </a>
             <h4><a href="http://rtcamp.com/products/buddypress-media-instagram/?utm_source=dashboard&amp;utm_medium=plugin&amp;utm_campaign=buddypress-media&amp;utm_content=bp-album-importer" title="BuddyPress-Media Instagram" target="_blank">BuddyPress-Media Instagram</a></h4>
             <div class="product_desc">
                 <p>' . __('BuddyPress Media Instagram adds Instagram like filters to images uploaded with BuddyPress Media.', 'rtmedia') . '</p>
                 <p><strong>' . __('Important', 'rtmedia') . ':</strong> ' . __('You need to have ImageMagick installed on your server for this addon to work.', 'rtmedia') . '</p>
             </div>
             <div class="product_footer">
                 <span class="price alignleft"><span class="amount">$19</span></span>
                 <a class="add_to_cart_button  alignright product_type_simple" href="http://rtcamp.com/products/?utm_source=dashboard&amp;utm_medium=plugin&amp;utm_campaign=buddypress-media&amp;utm_content=bp-album-importer&amp;add-to-cart=34379" target="_blank">' . __('Buy Now', 'rtmedia') . '</a>
                 <a class="alignleft product_demo_link" href="http://demo.rtcamp.com/rtmedia/?utm_source=dashboard&amp;utm_medium=plugin&amp;utm_campaign=buddypress-media&amp;utm_content=bp-album-importer" title="BuddyPress-Media Instagram" target="_blank">' . __('Live Demo', 'rtmedia') . '</a>
             </div></div>';
         }
         echo '</div>';
     } else {
         echo '<p>' . __('Looks like you don\'t use BP Album. Is there any other BuddyPress Plugin you want an importer for?', 'rtmedia') . '</p>';
         echo '<p>' . sprintf(__('<a href="%s">Create an issue</a> on GitHub requesting the same.', 'rtmedia'), 'https://github.com/rtCamp/rtMedia/issues/new') . '</p>';
     }
 }