| @@ -1,93 +1,92 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - | |
| 4 | 3 | namespace Boxzilla\Admin; |
| 5 | 4 | |
| 6 | -class Installer { | |
| 5 | +class Installer | |
| 6 | +{ | |
| 7 | + /** | |
| 8 | + * Run the installer | |
| 9 | + */ | |
| 10 | + public static function run() | |
| 11 | + { | |
| 12 | + $installer = new self(); | |
| 13 | + $installer->install(); | |
| 14 | + } | |
| 7 | 15 | |
| 8 | - /** | |
| 9 | - * Run the installer | |
| 10 | - */ | |
| 11 | - public static function run() { | |
| 12 | - $installer = new self; | |
| 13 | - $installer->install(); | |
| 14 | - } | |
| 16 | + /** | |
| 17 | + * The main install method | |
| 18 | + */ | |
| 19 | + public function install() | |
| 20 | + { | |
| 21 | + // don't install sample boxes on multisite | |
| 22 | + if (is_multisite()) { | |
| 23 | + return; | |
| 24 | + } | |
| 15 | 25 | |
| 16 | - /** | |
| 17 | - * The main install method | |
| 18 | - */ | |
| 19 | - public function install() { | |
| 26 | + $this->transfer_from_stb(); | |
| 27 | + $this->create_sample_box(); | |
| 28 | + } | |
| 20 | 29 | |
| 21 | - // don't install sample boxes on multisite | |
| 22 | - if( is_multisite() ) { | |
| 23 | - return; | |
| 24 | - } | |
| 30 | + /** | |
| 31 | + * | |
| 32 | + */ | |
| 33 | + public function transfer_from_stb() | |
| 34 | + { | |
| 35 | + global $wpdb; | |
| 25 | 36 | |
| 26 | - $this->transfer_from_stb(); | |
| 27 | - $this->create_sample_box(); | |
| 28 | - } | |
| 37 | + // transfer post types | |
| 38 | + $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_type = %s WHERE post_type = %s", 'boxzilla-box', 'scroll-triggered-box')); | |
| 29 | 39 | |
| 30 | - /** | |
| 31 | - * | |
| 32 | - */ | |
| 33 | - public function transfer_from_stb() { | |
| 34 | - global $wpdb; | |
| 40 | + // transfer post meta | |
| 41 | + $wpdb->query($wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_key = %s WHERE meta_key = %s", 'boxzilla_options', 'stb_options')); | |
| 35 | 42 | |
| 36 | - // transfer post types | |
| 37 | - $query = $wpdb->prepare( "UPDATE {$wpdb->posts} SET post_type = %s WHERE post_type = %s", 'boxzilla-box', 'scroll-triggered-box' ); | |
| 38 | - $wpdb->query( $query ); | |
| 43 | + // transfer rules | |
| 44 | + $wpdb->query($wpdb->prepare("UPDATE {$wpdb->options} SET option_name = %s WHERE option_name = %s", 'boxzilla_rules', 'stb_rules')); | |
| 45 | + } | |
| 39 | 46 | |
| 40 | - // transfer post meta | |
| 41 | - $query = $wpdb->prepare( "UPDATE {$wpdb->postmeta} SET meta_key = %s WHERE meta_key = %s", 'boxzilla_options', 'stb_options' ); | |
| 42 | - $wpdb->query( $query ); | |
| 47 | + /** | |
| 48 | + * @return bool | |
| 49 | + */ | |
| 50 | + protected function create_sample_box() | |
| 51 | + { | |
| 43 | 52 | |
| 44 | - // transfer rules | |
| 45 | - $query = $wpdb->prepare( "UPDATE {$wpdb->options} SET option_name = %s WHERE option_name = %s", 'boxzilla_rules', 'stb_rules' ); | |
| 46 | - $wpdb->query( $query ); | |
| 47 | - } | |
| 53 | + // only create sample box if no boxes were found | |
| 54 | + $boxes = get_posts( | |
| 55 | + [ | |
| 56 | + 'post_type' => 'boxzilla-box', | |
| 57 | + 'post_status' => [ 'publish', 'draft' ], | |
| 58 | + ] | |
| 59 | + ); | |
| 48 | 60 | |
| 49 | - /** | |
| 50 | - * @return bool | |
| 51 | - */ | |
| 52 | - protected function create_sample_box() { | |
| 61 | + if (! empty($boxes)) { | |
| 62 | + return false; | |
| 63 | + } | |
| 53 | 64 | |
| 54 | - // only create sample box if no boxes were found | |
| 55 | - $boxes = get_posts( | |
| 56 | - array( | |
| 57 | - 'post_type' => 'boxzilla-box', | |
| 58 | - 'post_status' => array( 'publish', 'draft' ) | |
| 59 | - ) | |
| 60 | - ); | |
| 65 | + $box_id = wp_insert_post( | |
| 66 | + [ | |
| 67 | + 'post_type' => 'boxzilla-box', | |
| 68 | + 'post_title' => 'Sample Box', | |
| 69 | + 'post_content' => '<h4>Hello world.</h4><p>This is a sample box, with some sample content in it.</p>', | |
| 70 | + 'post_status' => 'draft', | |
| 71 | + ] | |
| 72 | + ); | |
| 61 | 73 | |
| 62 | - if( ! empty( $boxes ) ) { | |
| 63 | - return false; | |
| 64 | - } | |
| 74 | + // set box settings | |
| 75 | + $settings = [ | |
| 76 | + 'css' => [ | |
| 77 | + 'background_color' => '#edf9ff', | |
| 78 | + 'color' => '', | |
| 79 | + 'width' => '340', | |
| 80 | + 'border_color' => '#dd7575', | |
| 81 | + 'border_width' => '4', | |
| 82 | + 'border_style' => 'dashed', | |
| 83 | + 'position' => 'bottom-right', | |
| 84 | + 'manual' => '', | |
| 85 | + ], | |
| 86 | + ]; | |
| 65 | 87 | |
| 66 | - $box_id = wp_insert_post( | |
| 67 | - array( | |
| 68 | - 'post_type' => 'boxzilla-box', | |
| 69 | - 'post_title' => "Sample Box", | |
| 70 | - 'post_content' => "<h4>Hello world.</h4><p>This is a sample box, with some sample content in it.</p>", | |
| 71 | - 'post_status' => 'draft', | |
| 72 | - ) | |
| 73 | - ); | |
| 88 | + update_post_meta($box_id, 'boxzilla_options', $settings); | |
| 74 | 89 | |
| 75 | - // set box settings | |
| 76 | - $settings = array( | |
| 77 | - 'css' => array( | |
| 78 | - 'background_color' => '#edf9ff', | |
| 79 | - 'color' => '', | |
| 80 | - 'width' => '340', | |
| 81 | - 'border_color' => '#dd7575', | |
| 82 | - 'border_width' => '4', | |
| 83 | - 'border_style' => 'dashed', | |
| 84 | - 'position' => 'bottom-right', | |
| 85 | - 'manual' => '' | |
| 86 | - ) | |
| 87 | - ); | |
| 88 | - | |
| 89 | - update_post_meta( $box_id, 'boxzilla_options', $settings ); | |
| 90 | - | |
| 91 | - return true; | |
| 92 | - } | |
| 93 | -} | |
| 90 | + return true; | |
| 91 | + } | |
| 92 | +} | |