| 1 |
<?php |
| 2 |
|
| 3 |
namespace RadiusTheme\SB\Modules\Compare; |
| 4 |
|
| 5 |
use RadiusTheme\SB\Helpers\Fns; |
| 6 |
|
| 7 |
// Do not allow directly accessing this file. |
| 8 |
if ( ! defined( 'ABSPATH' ) ) { |
| 9 |
exit( 'This script cannot be accessed directly.' ); |
| 10 |
} |
| 11 |
|
| 12 |
|
| 13 |
class CompareInstaller { |
| 14 |
|
| 15 |
/** |
| 16 |
* Run the installer |
| 17 |
* |
| 18 |
* @return void |
| 19 |
*/ |
| 20 |
public function run() { |
| 21 |
$this->create_page(); |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* [create_page] Create page |
| 26 |
* |
| 27 |
* @return void [void] |
| 28 |
*/ |
| 29 |
private function create_page() { |
| 30 |
|
| 31 |
$page_id = Fns::get_option( 'modules', 'compare', 'page', 0, 'number' ); |
| 32 |
if ( $page_id > 0 ) { |
| 33 |
$page_object = get_post( $page_id ); |
| 34 |
|
| 35 |
if ( $page_object && 'page' === $page_object->post_type && ! in_array( |
| 36 |
$page_object->post_status, |
| 37 |
[ |
| 38 |
'pending', |
| 39 |
'trash', |
| 40 |
'future', |
| 41 |
'auto-draft', |
| 42 |
], |
| 43 |
true |
| 44 |
) ) { |
| 45 |
// Valid page is already in place. |
| 46 |
return; |
| 47 |
} |
| 48 |
} |
| 49 |
if ( function_exists( 'WC' ) ) { |
| 50 |
if ( ! function_exists( 'wc_create_page' ) ) { |
| 51 |
require_once WC_ABSPATH . '/includes/admin/wc-admin-functions.php'; |
| 52 |
} |
| 53 |
$create_page_id = wc_create_page( |
| 54 |
sanitize_title_with_dashes( _x( 'compare', 'page_slug', 'shopbuilder' ) ), |
| 55 |
'', |
| 56 |
esc_html__( 'Compare', 'shopbuilder' ), |
| 57 |
'<!-- wp:shortcode -->[rtsb_compare_list]<!-- /wp:shortcode -->' |
| 58 |
); |
| 59 |
if ( $create_page_id ) { |
| 60 |
$section_items = []; |
| 61 |
$section_items['page'] = strval( $create_page_id ); |
| 62 |
Fns::set_options( 'modules', 'compare', $section_items ); |
| 63 |
|
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
} |
| 68 |
|