'Lumora', 'logo' => 'lumora.png', 'content' => self::content( __( 'Lumora is a drag-and-drop website builder aimed at small businesses. Every plan includes hosting, a free SSL certificate and round-the-clock live chat, so you can launch a professional site without hiring a developer.', 'affiliate-reviews' ), __( 'The editor is the easiest of the builders we tested: sections snap into place, and the templates look good on phones without extra work. Pages loaded fast on every plan. The catch is that selling online needs one of the higher plans.', 'affiliate-reviews' ) ), 'meta' => array( 'affreviews_rating' => '4.6', 'affreviews_bonus' => __( 'Save 40% on annual plans', 'affiliate-reviews' ), 'affreviews_description' => __( 'Lumora is a drag-and-drop website builder with fast hosting, a free SSL certificate and 24/7 live chat included in every plan. A good fit for small businesses that want a professional site without hiring a developer.', 'affiliate-reviews' ), 'affreviews_positives' => array( __( 'Intuitive drag-and-drop editor', 'affiliate-reviews' ), __( 'Free domain for the first year', 'affiliate-reviews' ), __( 'Fast page loads on every plan', 'affiliate-reviews' ), __( 'Helpful 24/7 live chat', 'affiliate-reviews' ), ), 'affreviews_negatives' => array( __( 'Online store only on higher plans', 'affiliate-reviews' ), __( 'Switching templates resets some styling', 'affiliate-reviews' ), ), 'affreviews_group_info_list' => array( array( 'title' => __( 'Starting price', 'affiliate-reviews' ), 'value' => __( '$12.99 / month', 'affiliate-reviews' ), ), array( 'title' => __( 'Free trial', 'affiliate-reviews' ), 'value' => __( '14 days', 'affiliate-reviews' ), ), array( 'title' => __( 'Money-back guarantee', 'affiliate-reviews' ), 'value' => __( '30 days', 'affiliate-reviews' ), ), array( 'title' => __( 'Support', 'affiliate-reviews' ), 'value' => __( '24/7 live chat', 'affiliate-reviews' ), ), ), 'affreviews_afflink' => 'https://example.com/', 'affreviews_terms' => __( 'Discount applies to the first billing term. Prices exclude VAT.', 'affiliate-reviews' ), 'affreviews_tag_text' => __( 'Best Overall', 'affiliate-reviews' ), 'affreviews_logo_background_color' => '#2563eb', ), ), array( 'title' => 'Pagecraft', 'logo' => 'pagecraft.png', 'content' => self::content( __( 'Pagecraft keeps costs down without cutting the features most sites need: a visual editor, a blog, contact forms and basic SEO settings are in every plan.', 'affiliate-reviews' ), __( 'Its templates are simpler than Lumora\'s and support answers by email and chat during business hours only, but for a portfolio or a local business site it is hard to beat on price.', 'affiliate-reviews' ) ), 'meta' => array( 'affreviews_rating' => '4.3', 'affreviews_bonus' => __( 'First 3 months for $1', 'affiliate-reviews' ), 'affreviews_description' => __( 'Pagecraft is a budget-friendly website builder with a visual editor, a built-in blog and SEO tools in every plan. Ideal for portfolios and local businesses.', 'affiliate-reviews' ), 'affreviews_positives' => array( __( 'Lowest price of the builders we tested', 'affiliate-reviews' ), __( 'Blog and SEO tools on every plan', 'affiliate-reviews' ), __( 'Clean, beginner-friendly editor', 'affiliate-reviews' ), ), 'affreviews_negatives' => array( __( 'Fewer templates to choose from', 'affiliate-reviews' ), __( 'Support only during business hours', 'affiliate-reviews' ), ), 'affreviews_group_info_list' => array( array( 'title' => __( 'Starting price', 'affiliate-reviews' ), 'value' => __( '$8.99 / month', 'affiliate-reviews' ), ), array( 'title' => __( 'Free trial', 'affiliate-reviews' ), 'value' => __( '7 days', 'affiliate-reviews' ), ), array( 'title' => __( 'Money-back guarantee', 'affiliate-reviews' ), 'value' => __( '14 days', 'affiliate-reviews' ), ), array( 'title' => __( 'Support', 'affiliate-reviews' ), 'value' => __( 'Email and chat, business hours', 'affiliate-reviews' ), ), ), 'affreviews_afflink' => 'https://example.com/', 'affreviews_terms' => __( 'Introductory price for new customers, then regular rates apply.', 'affiliate-reviews' ), 'affreviews_tag_text' => __( 'Best Value', 'affiliate-reviews' ), 'affreviews_logo_background_color' => '#ea580c', ), ), array( 'title' => 'Sitewave', 'logo' => 'sitewave.png', 'content' => self::content( __( 'Sitewave has the most generous free plan of the three: you can build and publish a complete site on a Sitewave subdomain without entering a card.', 'affiliate-reviews' ), __( 'The free plan shows a small Sitewave badge, and custom domains, email and online payments need a paid plan. Upgrading later keeps everything you built, which makes it a low-risk way to start.', 'affiliate-reviews' ) ), 'meta' => array( 'affreviews_rating' => '4.1', 'affreviews_bonus' => __( 'Free plan, no card needed', 'affiliate-reviews' ), 'affreviews_description' => __( 'Sitewave lets you build and publish a complete website for free, then upgrade for a custom domain and online payments when you are ready.', 'affiliate-reviews' ), 'affreviews_positives' => array( __( 'Generous free plan', 'affiliate-reviews' ), __( 'Upgrade anytime without rebuilding', 'affiliate-reviews' ), __( 'Good selection of modern templates', 'affiliate-reviews' ), ), 'affreviews_negatives' => array( __( 'Badge on free sites', 'affiliate-reviews' ), __( 'Custom domain only on paid plans', 'affiliate-reviews' ), ), 'affreviews_group_info_list' => array( array( 'title' => __( 'Starting price', 'affiliate-reviews' ), 'value' => __( 'Free, paid from $16 / month', 'affiliate-reviews' ), ), array( 'title' => __( 'Free trial', 'affiliate-reviews' ), 'value' => __( 'Free plan', 'affiliate-reviews' ), ), array( 'title' => __( 'Money-back guarantee', 'affiliate-reviews' ), 'value' => __( '30 days', 'affiliate-reviews' ), ), array( 'title' => __( 'Support', 'affiliate-reviews' ), 'value' => __( '24/7 email', 'affiliate-reviews' ), ), ), 'affreviews_afflink' => 'https://example.com/', 'affreviews_terms' => __( 'Paid plans billed annually. Taxes may apply.', 'affiliate-reviews' ), 'affreviews_tag_text' => __( 'Best Free Plan', 'affiliate-reviews' ), 'affreviews_logo_background_color' => '#7c3aed', ), ), ); } /** * Review body: an intro and a verdict, as paragraph blocks. * * @param string $intro First paragraph. * @param string $verdict Second paragraph. * @return string */ private static function content( $intro, $verdict ) { return '
' . esc_html( $intro ) . '
' . "\n\n" . '' . esc_html( $verdict ) . '
'; } /** * IDs of the imported demo reviews. Trashed ones count as removed: the * user deleted them, and WordPress empties the trash in time. * * @return int[] */ public static function get_ids() { return get_posts( array( 'post_type' => AFFREVIEWS_CPT, 'post_status' => array( 'publish', 'future', 'draft', 'pending', 'private' ), 'posts_per_page' => -1, 'fields' => 'ids', 'meta_key' => self::DEMO_META, // phpcs:ignore WordPress.DB.SlowDBQuery -- A handful of rows, admin only. ) ); } /** * Whether the site has any reviews (demo or not), trashed ones aside. * * @return bool */ public static function has_reviews() { $counts = (array) wp_count_posts( AFFREVIEWS_CPT ); unset( $counts['trash'], $counts['auto-draft'] ); return array_sum( $counts ) > 0; } /** * Create the demo reviews, their logos and their category. * * @return int[]|WP_Error IDs of the new reviews. */ public static function import() { if ( self::get_ids() ) { return new WP_Error( 'affreviews_demo_exists', __( 'The demo reviews are already imported.', 'affiliate-reviews' ), array( 'status' => 409 ) ); } require_once ABSPATH . 'wp-admin/includes/image.php'; $term_id = self::get_category(); $ids = array(); $time = time(); // Oldest first, so the first review is the latest (and previewed in the editor). foreach ( array_reverse( self::reviews() ) as $index => $review ) { $meta = $review['meta']; $meta[ self::DEMO_META ] = 1; $date = $time - ( count( self::reviews() ) - $index ) * MINUTE_IN_SECONDS; $post_id = wp_insert_post( array( 'post_type' => AFFREVIEWS_CPT, 'post_status' => 'publish', 'post_title' => $review['title'], 'post_content' => $review['content'], 'post_date' => wp_date( 'Y-m-d H:i:s', $date ), 'post_date_gmt' => gmdate( 'Y-m-d H:i:s', $date ), 'meta_input' => $meta, ), true ); if ( is_wp_error( $post_id ) ) { self::remove(); return $post_id; } $ids[] = $post_id; if ( $term_id ) { wp_set_object_terms( $post_id, $term_id, AFFREVIEWS_TAX ); } $logo_id = self::import_logo( $review['logo'], $review['title'], $post_id ); if ( $logo_id ) { set_post_thumbnail( $post_id, $logo_id ); } } delete_option( self::NOTICE_OPTION ); return array_reverse( $ids ); } /** * The demo category: an existing "Website Builders" category, or a new * one flagged as demo content. * * @return int Term ID, or 0 when it can't be created. */ private static function get_category() { $name = __( 'Website Builders', 'affiliate-reviews' ); $existing = term_exists( $name, AFFREVIEWS_TAX ); if ( $existing ) { return (int) $existing['term_id']; } $term = wp_insert_term( $name, AFFREVIEWS_TAX ); if ( is_wp_error( $term ) ) { return 0; } update_term_meta( $term['term_id'], self::DEMO_META, 1 ); return (int) $term['term_id']; } /** * Copy a bundled logo to the uploads folder and add it to the media * library, attached to its review. * * @param string $file File name in admin/assets/demo. * @param string $title Attachment title. * @param int $post_id Review ID. * @return int Attachment ID, or 0 on failure. */ private static function import_logo( $file, $title, $post_id ) { $source = AFFREVIEWS_DIR . 'admin/assets/demo/' . $file; if ( ! is_readable( $source ) ) { return 0; } $upload = wp_upload_bits( 'affreviews-demo-' . $file, null, file_get_contents( $source ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local file. if ( ! empty( $upload['error'] ) ) { return 0; } $attachment_id = wp_insert_attachment( array( 'post_mime_type' => 'image/png', /* translators: %s: brand name. */ 'post_title' => sprintf( __( '%s logo', 'affiliate-reviews' ), $title ), 'post_status' => 'inherit', ), $upload['file'], $post_id, true ); if ( is_wp_error( $attachment_id ) ) { wp_delete_file( $upload['file'] ); return 0; } update_post_meta( $attachment_id, self::DEMO_META, 1 ); wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $upload['file'] ) ); return $attachment_id; } /** * Delete the demo reviews, their logos, and the demo category when no * other review uses it. * * @return int Number of reviews deleted. */ public static function remove() { $ids = self::get_ids(); foreach ( $ids as $post_id ) { $logos = get_posts( array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'post_parent' => $post_id, 'posts_per_page' => -1, 'fields' => 'ids', 'meta_key' => self::DEMO_META, // phpcs:ignore WordPress.DB.SlowDBQuery -- A handful of rows, admin only. ) ); foreach ( $logos as $logo_id ) { wp_delete_attachment( $logo_id, true ); } wp_delete_post( $post_id, true ); } $terms = get_terms( array( 'taxonomy' => AFFREVIEWS_TAX, 'hide_empty' => false, 'meta_key' => self::DEMO_META, // phpcs:ignore WordPress.DB.SlowDBQuery -- A handful of rows, admin only. ) ); foreach ( is_array( $terms ) ? $terms : array() as $term ) { if ( ! get_objects_in_term( $term->term_id, AFFREVIEWS_TAX ) ) { wp_delete_term( $term->term_id, AFFREVIEWS_TAX ); } } return count( $ids ); } /** * The imported demo reviews, for the settings page. * * @return array[] */ public static function status() { $reviews = array(); foreach ( self::get_ids() as $post_id ) { $reviews[] = array( 'id' => $post_id, 'title' => get_the_title( $post_id ), 'status' => get_post_status( $post_id ), 'edit' => (string) get_edit_post_link( $post_id, 'raw' ), ); } return array( 'reviews' => $reviews ); } /** * Activation: offer the demo while the site has no reviews. * * @return void */ public static function activate() { if ( ! self::has_reviews() ) { update_option( self::NOTICE_OPTION, 1, false ); } } /** * Register the demo REST routes: GET lists the demo reviews, POST imports * them, DELETE removes them. * * @return void */ public function register_routes() { $permission = function () { return current_user_can( 'manage_options' ); }; register_rest_route( 'affreviews/v1', '/demo', array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => function () { return rest_ensure_response( self::status() ); }, 'permission_callback' => $permission, ), array( 'methods' => WP_REST_Server::CREATABLE, 'callback' => function () { $result = self::import(); return is_wp_error( $result ) ? $result : rest_ensure_response( self::status() ); }, 'permission_callback' => $permission, ), array( 'methods' => WP_REST_Server::DELETABLE, 'callback' => function () { self::remove(); return rest_ensure_response( self::status() ); }, 'permission_callback' => $permission, ), ) ); } /** * After activation, while the site has no reviews: offer to import the * demo reviews. * * @return void */ public function admin_notice() { if ( ! get_option( self::NOTICE_OPTION ) || ! current_user_can( 'manage_options' ) ) { return; } if ( self::has_reviews() ) { delete_option( self::NOTICE_OPTION ); return; } $import_url = wp_nonce_url( admin_url( 'admin-post.php?action=affreviews_import_demo' ), 'affreviews_import_demo' ); $dismiss_url = wp_nonce_url( admin_url( 'admin-post.php?action=affreviews_dismiss_demo' ), 'affreviews_dismiss_demo' ); ?> 'affreviews-settings', 'tab' => 'demo', ), admin_url( 'admin.php' ) ) ); exit; } /** * Dismiss the activation notice. * * @return void */ public function handle_dismiss() { check_admin_referer( 'affreviews_dismiss_demo' ); if ( current_user_can( 'manage_options' ) ) { delete_option( self::NOTICE_OPTION ); } wp_safe_redirect( wp_get_referer() ? wp_get_referer() : admin_url() ); exit; } }