get_col('SELECT ID FROM '.$wpdb->posts.' WHERE post_type = "mbt_book"'); if(!empty($books)) { foreach($books as $book_id) { $image_id = get_post_meta($book_id, '_thumbnail_id', true); $mbt_book_image_id = get_post_meta($book_id, 'mbt_book_image_id', true); if(empty($mbt_book_image_id) && !empty($image_id)) { update_post_meta($book_id, 'mbt_book_image_id', $image_id); } } } } function mbt_update_1_1_4() { global $wpdb; $books = $wpdb->get_col('SELECT ID FROM '.$wpdb->posts.' WHERE post_type = "mbt_book"'); if(!empty($books)) { foreach($books as $book_id) { delete_post_meta($book_id, '_thumbnail_id'); $buybuttons = get_post_meta($book_id, 'mbt_buybuttons', true); if(is_array($buybuttons) and !empty($buybuttons)) { for($i = 0; $i < count($buybuttons); $i++) { if($buybuttons[$i]['type']) { $buybuttons[$i]['store'] = $buybuttons[$i]['type']; unset($buybuttons[$i]['type']); } } } update_post_meta($book_id, 'mbt_buybuttons', $buybuttons); } } } function mbt_update_1_2_7() { if(mbt_get_setting('enable_default_affiliates') !== false) { mbt_update_setting('enable_default_affiliates', true); } } function mbt_update_1_3_1() { //mbt_update_setting('help_page_email_subscribe_popup', 'show'); mbt_update_setting('product_name', __("Books", 'mybooktable')); mbt_update_setting('product_slug', _x('books', 'URL slug', 'mybooktable')); } function mbt_update_1_3_8() { mbt_update_setting('domc_notice_text', esc_attr_e('Disclosure of Material Connection: Some of the links in the page above are "affiliate links." This means if you click on the link and purchase the item, I will receive an affiliate commission. I am disclosing this in accordance with the Federal Trade Commission\'s 16 CFR, Part 255: "Guides Concerning the Use of Endorsements and Testimonials in Advertising."', 'mybooktable')); } function mbt_update_2_0_1() { mbt_verify_api_key(); } function mbt_update_2_0_4() { mbt_update_setting('show_find_bookstore_buybuttons_shadowbox', true); } function mbt_update_2_1_0() { global $wpdb; $books = $wpdb->get_col('SELECT ID FROM '.$wpdb->posts.' WHERE post_type = "mbt_book"'); if(!empty($books)) { foreach($books as $book_id) { $buybuttons = get_post_meta($book_id, 'mbt_buybuttons', true); if(is_array($buybuttons) and !empty($buybuttons)) { for($i = 0; $i < count($buybuttons); $i++) { $buybuttons[$i]['display'] = ($buybuttons[$i]['display'] == 'text_only' or $buybuttons[$i]['display'] == 'text') ? 'text' : 'button'; } } update_post_meta($book_id, 'mbt_buybuttons', $buybuttons); } } mbt_update_setting('buybutton_shadowbox', mbt_get_setting('enable_buybutton_shadowbox') ? 'all' : 'none'); } function mbt_update_2_2_0() { global $wpdb; $books = $wpdb->get_col('SELECT ID FROM '.$wpdb->posts.' WHERE post_type = "mbt_book"'); if(!empty($books)) { foreach($books as $book_id) { update_post_meta($book_id, 'mbt_unique_id_isbn', get_post_meta($book_id, 'mbt_unique_id', true)); } } } function mbt_update_2_3_0() { $style_pack = mbt_get_setting('style_pack'); if($style_pack == 'Default') { mbt_update_setting('style_pack', 'silver'); } if($style_pack == 'Golden') { mbt_update_setting('style_pack', 'golden'); } if($style_pack == 'Blue Flat') { mbt_update_setting('style_pack', 'blue_flat'); } if($style_pack == 'Gold Flat') { mbt_update_setting('style_pack', 'gold_flat'); } if($style_pack == 'Green Flat') { mbt_update_setting('style_pack', 'green_flat'); } if($style_pack == 'Grey Flat') { mbt_update_setting('style_pack', 'grey_flat'); } if($style_pack == 'Orange Flat') { mbt_update_setting('style_pack', 'orange_flat'); } } function mbt_update_3_0_0() { mbt_update_setting('show_about_author', true); mbt_update_setting('reviews_type', mbt_get_setting('reviews_box')); mbt_update_setting('enable_socialmedia_single_book', mbt_get_setting('enable_socialmedia_badges_single_book') or mbt_get_setting('enable_socialmedia_bar_single_book')); mbt_update_setting('enable_socialmedia_book_excerpt', mbt_get_setting('enable_socialmedia_badges_book_excerpt')); $books_query = new WP_Query(array('post_type' => 'mbt_book', 'posts_per_page' => -1)); foreach ($books_query->posts as $book) { update_post_meta($book->ID, 'mbt_display_mode', 'storefront'); if(get_post_meta($book->ID, 'mbt_unique_id_asin', true) == '') { $buybuttons = get_post_meta($book->ID, 'mbt_buybuttons', true); if(is_array($buybuttons) and !empty($buybuttons)) { foreach($buybuttons as $buybutton) { if($buybutton['store'] == 'amazon' or $buybutton['store'] == 'kindle') { $asin = mbt_get_amazon_AISN($buybutton['url']); if(!empty($asin)) { update_post_meta($book->ID, 'mbt_unique_id_asin', $asin); } break; } } } } } } /*---------------------------------------------------------*/ /* Rewrites Check */ /*---------------------------------------------------------*/ function mbt_rewrites_check_init() { add_action('wp_loaded', 'mbt_rewrites_check', 999); } add_action('mbt_init', 'mbt_rewrites_check_init'); function mbt_rewrites_check() { if(!mbt_check_rewrites()) { flush_rewrite_rules(); if(!mbt_check_rewrites()) { add_action('admin_notices', 'mbt_rewrites_check_admin_notice'); } } } function mbt_check_rewrites() { global $pagenow; $settings_updated = filter_input(INPUT_GET,'settings-updated'); if($pagenow == 'options-permalink.php' and !empty($settings_updated)) { return true; } global $wp_rewrite; $rules = $wp_rewrite->wp_rewrite_rules(); if(empty($rules) or !is_array($rules)) { return true; } $book_page_correct = false; $books = new WP_Query(array('post_type' => 'mbt_book', 'post_status' => 'publish', 'posts_per_page' => 1)); if(empty($books->posts)) { $book_page_correct = true; } else { $book = $books->posts[0]; $book_page_correct = mbt_get_rewrite($rules, get_permalink($book)) === 'index.php?mbt_book=$matches[1]&page=$matches[2]'; } $archive_correct = mbt_get_rewrite($rules, get_post_type_archive_link('mbt_book')) === 'index.php?post_type=mbt_book'; $genres_correct = mbt_check_tax_rewrites($rules, 'mbt_genre'); $authors_correct = mbt_check_tax_rewrites($rules, 'mbt_author'); $series_correct = mbt_check_tax_rewrites($rules, 'mbt_series'); $tags_correct = mbt_check_tax_rewrites($rules, 'mbt_tag'); return $archive_correct and $book_page_correct and $genres_correct and $authors_correct and $series_correct and $tags_correct; } function mbt_check_tax_rewrites($rules, $tax) { $terms = get_terms($tax); if(empty($terms)) { return true; } return mbt_get_rewrite($rules, get_term_link(reset($terms), $tax)) === 'index.php?'.$tax.'=$matches[1]'; } function mbt_get_rewrite($rules, $url) { $parts = wp_parse_url(home_url('/')); $default_path = $parts['path']; $parts = wp_parse_url($url); $url = $parts['path']; $url = substr($url, strlen($default_path)); foreach($rules as $match => $query) { if(preg_match("#^$match#", $url)) { return $query; } } return ''; } function mbt_rewrites_check_admin_notice() { ?>

'.esc_attr_e('Welcome to MyBookTable', 'mybooktable').' – '.esc_attr_e("You're almost ready to start promoting your books", 'mybooktable').' :)'); ?>

'.esc_attr_e('MyBookTable has been installed', 'mybooktable').' – '.esc_attr_e("You're ready to start promoting your books", 'mybooktable').' :)'); ?>

'.esc_attr_e('Setup your License Key', 'mybooktable').' – '.esc_attr_e('MyBookTable needs your License key to enable enhanced features', 'mybooktable')); ?>

'.esc_attr_e('Setup your Amazon and Barnes & Noble Buttons', 'mybooktable').' – '.esc_attr_e('MyBookTable needs your input to enable these features', 'mybooktable')); ?>

'.esc_attr_e('Enable your Upgrade', 'mybooktable').' – '.esc_attr_e('Download or Activate your MyBookTable Upgrade plugin to enable your advanced features!', 'mybooktable')); ?>

esc_attr_e('Book Table', 'mybooktable'), 'post_content' => '', 'post_status' => 'publish', 'post_type' => 'page' )); mbt_update_setting("booktable_page", $post_id); } } function mbt_install_examples() { if(!mbt_get_setting('installed_examples')) { include("examples.php"); mbt_update_setting('installed_examples', true); } }