Plugin Directory

Changeset 3313497


Ignore:
Timestamp:
06/17/2025 08:25:17 PM (10 months ago)
Author:
elevation1support
Message:

Fixed images urls paths for demo import

Location:
elevation-blocks
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • elevation-blocks/tags/1.0.4/lib/admin/controls/class-helpers.php

    r3313416 r3313497  
    11<?php
     2
    23/**
    34 * File Name: class-helpers.php
     
    1011namespace ElevationBlocks\Lib\Admin\Controls;
    1112
    12 if ( ! defined( 'ABSPATH' ) ) {
     13if (! defined('ABSPATH')) {
    1314    exit;
    1415}
     
    1718 * Class Helpers
    1819 */
    19 class Helpers {
     20class Helpers
     21{
    2022
    2123
     
    3234     * @return void
    3335     */
    34     public function __construct() {
    35         add_action( 'admin_menu', array( $this, 'elevation_blocks_import_admin_menu' ) );
     36    public function __construct()
     37    {
     38        add_action('admin_menu', array($this, 'elevation_blocks_import_admin_menu'));
    3639    }
    3740
     
    4144     * @return html
    4245     */
    43     public function elevation_blocks_import_page_html() {
    44         if ( ! current_user_can( 'manage_options' ) ) {
     46    public function elevation_blocks_import_page_html()
     47    {
     48        if (! current_user_can('manage_options')) {
    4549            return;
    4650        }
    4751
    4852        // Handle import action.
    49         if ( isset( $_POST['import_demo_content'] ) ) {
     53        if (isset($_POST['import_demo_content'])) {
    5054            // Unslash the data before verification.
    51             $import_demo_nonce = isset( $_POST['import_demo_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['import_demo_nonce'] ) ) : '';
     55            $import_demo_nonce = isset($_POST['import_demo_nonce']) ? sanitize_text_field(wp_unslash($_POST['import_demo_nonce'])) : '';
    5256
    5357            // Verify the nonce after unslashing.
    54             if ( ! wp_verify_nonce( $import_demo_nonce, 'import_demo_nonce_action' ) ) {
    55                 wp_die( esc_html__( 'Nonce verification failed', 'elevation-blocks' ) );
     58            if (! wp_verify_nonce($import_demo_nonce, 'import_demo_nonce_action')) {
     59                wp_die(esc_html__('Nonce verification failed', 'elevation-blocks'));
    5660            }
    5761
     
    6468        }
    6569
    66         ?>
     70?>
    6771        <div class="wrap">
    68             <h1><?php echo esc_html__( 'Import Elevation Demo Content', 'elevation-blocks' ); ?></h1>
    69             <p><?php echo esc_html__( 'Click the button below to import default pages for your theme.', 'elevation-blocks' ); ?></p>
     72            <h1><?php echo esc_html__('Import Elevation Demo Content', 'elevation-blocks'); ?></h1>
     73            <p><?php echo esc_html__('Click the button below to import default pages for your theme.', 'elevation-blocks'); ?></p>
    7074            <form method="post">
    71                 <?php wp_nonce_field( 'import_demo_nonce_action', 'import_demo_nonce' ); ?>
    72                 <input type="submit" name="import_demo_content" class="button button-primary" value="<?php echo esc_attr__( 'Import Pages', 'elevation-blocks' ); ?>" onclick="return confirm('Are you sure you want to import demo content? This could overwrite existing content.');">
     75                <?php wp_nonce_field('import_demo_nonce_action', 'import_demo_nonce'); ?>
     76                <input type="submit" name="import_demo_content" class="button button-primary" value="<?php echo esc_attr__('Import Pages', 'elevation-blocks'); ?>" onclick="return confirm('Are you sure you want to import demo content? This could overwrite existing content.');">
    7377            </form>
    7478        </div>
    75         <?php
     79<?php
    7680    }
    7781
     
    8185     * @return void
    8286     */
    83     public function elevation_blocks_import_admin_menu() {
     87    public function elevation_blocks_import_admin_menu()
     88    {
    8489        add_management_page(
    85             esc_html__( 'Import Elevation Demo Content', 'elevation-blocks' ), // Page title.
    86             esc_html__( 'Import Elevation Demo Content', 'elevation-blocks' ),      // Menu title.
     90            esc_html__('Import Elevation Demo Content', 'elevation-blocks'), // Page title.
     91            esc_html__('Import Elevation Demo Content', 'elevation-blocks'),      // Menu title.
    8792            'manage_options',      // Capability.
    8893            'elevation-import',      // Menu slug.
    89             array( $this, 'elevation_blocks_import_page_html' ), // Callback function.
     94            array($this, 'elevation_blocks_import_page_html'), // Callback function.
    9095        );
    9196    }
     
    96101     * @return void
    97102     */
    98     public function elevation_blocks_import_demo_pages() {
     103    public function elevation_blocks_import_demo_pages()
     104    {
    99105        // Define the paths to the images.
    100106        $image_paths = array(
    101             'home-banner'         => plugin_dir_url( __DIR__ ) . 'assets/matthew-henry-2Ts5HnA67k8-unsplash.avif',
    102             'home-second-section' => plugin_dir_url( __DIR__ ) . 'assets/matthew-henry-U5rMrSI7Pn4-unsplash.avif',
    103             'about-banner'        => plugin_dir_url( __DIR__ ) . 'assets/paulo-simoes-mendes-V8YzvXKLwDw-unsplash.avif',
    104             'contact-banner'      => plugin_dir_url( __DIR__ ) . 'assets/samantha-sophia-NaWKMlp3tVs-unsplash.avif',
     107            'home-banner'         => ELEVATION_BLOCKS_DIR . 'assets/matthew-henry-2Ts5HnA67k8-unsplash.avif',
     108            'home-second-section' => ELEVATION_BLOCKS_DIR . 'assets/matthew-henry-U5rMrSI7Pn4-unsplash.avif',
     109            'about-banner'        => ELEVATION_BLOCKS_DIR . 'assets/paulo-simoes-mendes-V8YzvXKLwDw-unsplash.avif',
     110            'contact-banner'      => ELEVATION_BLOCKS_DIR . 'assets/samantha-sophia-NaWKMlp3tVs-unsplash.avif',
    105111        );
    106112
     113
    107114        $uploaded_images = array();
    108         foreach ( $image_paths as $key => $image_path ) {
    109             $uploaded_images[ $key ] = $this->elevation_blocks_upload_image( $image_path );
     115        foreach ($image_paths as $key => $image_path) {
     116            $uploaded_images[$key] = $this->elevation_blocks_upload_image($image_path);
    110117        }
    111118
     
    113120            array(
    114121                'title'   => 'Home',
    115                 'content' => $this->elevation_blocks_home_page( $uploaded_images ),
     122                'content' => $this->elevation_blocks_home_page($uploaded_images),
    116123            ),
    117124            array(
    118125                'title'   => 'About',
    119                 'content' => $this->elevation_blocks_about_page( $uploaded_images ),
     126                'content' => $this->elevation_blocks_about_page($uploaded_images),
    120127            ),
    121128            array(
    122129                'title'   => 'Contact',
    123                 'content' => $this->elevation_blocks_contact_page( $uploaded_images ),
     130                'content' => $this->elevation_blocks_contact_page($uploaded_images),
    124131            ),
    125132        );
    126133
    127         foreach ( $default_pages as $page ) {
     134        foreach ($default_pages as $page) {
    128135            // Check if the page already exists.
    129136            $page_query = new \WP_Query(
     
    138145            $existing_page = $page_query->have_posts();
    139146
    140             if ( ! $existing_page ) {
     147            if (! $existing_page) {
    141148                $page_id = wp_insert_post(
    142149                    array(
     
    148155                );
    149156
    150                 if ( 'Home' === $page['title'] ) {
    151                     update_option( 'show_on_front', 'page' ); // Set static page mode.
    152                     update_option( 'page_on_front', $page_id ); // Set the front page.
     157                if ('Home' === $page['title']) {
     158                    update_option('show_on_front', 'page'); // Set static page mode.
     159                    update_option('page_on_front', $page_id); // Set the front page.
    153160                }
    154161            }
     
    163170     * @return array
    164171     */
    165     private function elevation_blocks_upload_image( $file_path ) {
    166         if ( ! file_exists( $file_path ) ) {
     172    private function elevation_blocks_upload_image($file_path)
     173    {
     174        if (! file_exists($file_path)) {
    167175            return false;
    168176        }
    169177
    170         $file_name     = basename( $file_path );
     178        $file_name     = basename($file_path);
    171179        $upload_dir    = wp_upload_dir();
    172180        $new_file_path = $upload_dir['path'] . '/' . $file_name;
    173181
    174         if ( ! copy( $file_path, $new_file_path ) ) {
     182        if (! copy($file_path, $new_file_path)) {
    175183            return false;
    176184        }
    177185
    178         $file_type  = wp_check_filetype( $new_file_path, null );
     186        $file_type  = wp_check_filetype($new_file_path, null);
    179187        $attachment = array(
    180188            'post_mime_type' => $file_type['type'],
    181             'post_title'     => sanitize_file_name( $file_name ),
     189            'post_title'     => sanitize_file_name($file_name),
    182190            'post_content'   => '',
    183191            'post_status'    => 'inherit',
    184192        );
    185193
    186         $attach_id = wp_insert_attachment( $attachment, $new_file_path );
     194        $attach_id = wp_insert_attachment($attachment, $new_file_path);
    187195        require_once ABSPATH . 'wp-admin/includes/image.php';
    188         $attach_data = wp_generate_attachment_metadata( $attach_id, $new_file_path );
    189         wp_update_attachment_metadata( $attach_id, $attach_data );
    190 
    191         return array( $attach_id, wp_get_attachment_url( $attach_id ) ); // Return the image URL.
     196        $attach_data = wp_generate_attachment_metadata($attach_id, $new_file_path);
     197        wp_update_attachment_metadata($attach_id, $attach_data);
     198
     199        return array($attach_id, wp_get_attachment_url($attach_id)); // Return the image URL.
    192200    }
    193201
     
    199207     * @return array
    200208     */
    201     private function elevation_blocks_upload_image_from_url( $image_url ) {
    202         if ( ! filter_var( $image_url, FILTER_VALIDATE_URL ) ) {
     209    private function elevation_blocks_upload_image_from_url($image_url)
     210    {
     211
     212        if (! filter_var($image_url, FILTER_VALIDATE_URL)) {
    203213            return false;
    204214        }
    205215
    206216        // Get file contents.
    207         $response = wp_remote_get( $image_url );
    208 
    209         if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
     217        $response = wp_remote_get($image_url);
     218
     219
     220
     221        if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
    210222            return false;
    211223        }
    212224
    213         $image_data = wp_remote_retrieve_body( $response );
    214         if ( empty( $image_data ) ) {
     225        $image_data = wp_remote_retrieve_body($response);
     226        if (empty($image_data)) {
    215227            return false;
    216228        }
    217229
    218230        // Extract filename from URL.
    219         $file_name = basename( wp_parse_url( $image_url, PHP_URL_PATH ) );
     231        $file_name = basename(wp_parse_url($image_url, PHP_URL_PATH));
    220232
    221233        // Get upload directory.
    222234        $upload_dir    = wp_upload_dir();
    223         $new_file_path = trailingslashit( $upload_dir['path'] ) . $file_name;
     235        $new_file_path = trailingslashit($upload_dir['path']) . $file_name;
    224236
    225237        // Use WP_Filesystem to save the file.
     
    229241        WP_Filesystem();
    230242
    231         if ( ! $wp_filesystem->put_contents( $new_file_path, $image_data, FS_CHMOD_FILE ) ) {
     243        if (! $wp_filesystem->put_contents($new_file_path, $image_data, FS_CHMOD_FILE)) {
    232244            return false;
    233245        }
    234246
    235247        // Get file type.
    236         $file_type = wp_check_filetype( $file_name, null );
     248        $file_type = wp_check_filetype($file_name, null);
    237249
    238250        // Create attachment.
    239251        $attachment = array(
    240252            'post_mime_type' => $file_type['type'],
    241             'post_title'     => sanitize_file_name( $file_name ),
     253            'post_title'     => sanitize_file_name($file_name),
    242254            'post_content'   => '',
    243255            'post_status'    => 'inherit',
    244256        );
    245257
    246         $attach_id = wp_insert_attachment( $attachment, $new_file_path );
     258        $attach_id = wp_insert_attachment($attachment, $new_file_path);
     259
     260
    247261        require_once ABSPATH . 'wp-admin/includes/image.php';
    248         $attach_data = wp_generate_attachment_metadata( $attach_id, $new_file_path );
    249         wp_update_attachment_metadata( $attach_id, $attach_data );
    250 
    251         return array( $attach_id, wp_get_attachment_url( $attach_id ) ); // Return the image URL.
     262        $attach_data = wp_generate_attachment_metadata($attach_id, $new_file_path);
     263        wp_update_attachment_metadata($attach_id, $attach_data);
     264
     265        return array($attach_id, wp_get_attachment_url($attach_id)); // Return the image URL.
    252266    }
    253267
     
    263277     * @return string
    264278     */
    265     private function elevation_blocks_home_page( $uploaded_images ) {
    266         if ( empty( $uploaded_images['home-banner'] ) || empty( $uploaded_images['home-second-section'] ) ) {
     279    private function elevation_blocks_home_page($uploaded_images)
     280    {
     281        if (empty($uploaded_images['home-banner']) || empty($uploaded_images['home-second-section'])) {
    267282            return '';
    268283        }
     
    394409     * @return string
    395410     */
    396     private function elevation_blocks_about_page( $uploaded_images ) {
    397         if ( empty( $uploaded_images['about-banner'] ) ) {
     411    private function elevation_blocks_about_page($uploaded_images)
     412    {
     413        if (empty($uploaded_images['about-banner'])) {
    398414            return '';
    399415        }
     
    535551     * @return string
    536552     */
    537     private function elevation_blocks_contact_page( $uploaded_images ) {
    538         if ( empty( $uploaded_images['contact-banner'] ) ) {
     553    private function elevation_blocks_contact_page($uploaded_images)
     554    {
     555        if (empty($uploaded_images['contact-banner'])) {
    539556            return '';
    540557        }
     
    662679     * @return void
    663680     */
    664     public function elevation_blocks_add_default_widgets_to_sidebars() {
     681    public function elevation_blocks_add_default_widgets_to_sidebars()
     682    {
    665683        $this->elevation_blocks_update_option_wiget_block();
    666684        $this->elevation_blocks_update_option_sidebar_widgets();
     
    672690     * @return void
    673691     */
    674     public function elevation_blocks_update_option_wiget_block() {
     692    public function elevation_blocks_update_option_wiget_block()
     693    {
    675694        $content_2 = preg_replace(
    676695            '/\s+/',
     
    725744        );
    726745
    727         update_option( 'elevation_blocks_widget_block', $widget_block );
     746        update_option('elevation_blocks_widget_block', $widget_block);
    728747    }
    729748
     
    733752     * @return void
    734753     */
    735     public function elevation_blocks_update_option_sidebar_widgets() {
     754    public function elevation_blocks_update_option_sidebar_widgets()
     755    {
    736756        $sidebar_widgets = array(
    737757            'wp_inactive_widgets' =>
     
    750770        );
    751771
    752         update_option( 'elevation_blocks_sidebar_widgets', $sidebar_widgets );
     772        update_option('elevation_blocks_sidebar_widgets', $sidebar_widgets);
    753773    }
    754774
     
    758778     * @return void
    759779     */
    760     private function elevation_blocks_set_custom_image() {
     780    private function elevation_blocks_set_custom_image()
     781    {
    761782        // Define the image URL.
    762783        $header_image_url = ELEVATION_BLOCKS_DIR_URL . '/lib/admin/controls/images/logo-elevation.webp';
     
    764785
    765786        // Set the image URL programmatically in the customizer.
    766         set_theme_mod( 'custom_logo', $header_image_url );
    767         set_theme_mod( 'footer_logo', $footer_image_url );
     787        set_theme_mod('custom_logo', $header_image_url);
     788        set_theme_mod('footer_logo', $footer_image_url);
    768789    }
    769790
     
    773794     * @return void
    774795     */
    775     public function elevation_blocks_create_custom_menu() {
     796    public function elevation_blocks_create_custom_menu()
     797    {
    776798        // Define the menu name.
    777799        $menu_name = 'Main Menu';
    778800
    779801        // Check if the menu already exists.
    780         $menu_exists = wp_get_nav_menu_object( $menu_name );
     802        $menu_exists = wp_get_nav_menu_object($menu_name);
    781803
    782804        // Create menu if it doesn't exist.
    783         if ( ! $menu_exists ) {
    784             $menu_id = wp_create_nav_menu( $menu_name );
     805        if (! $menu_exists) {
     806            $menu_id = wp_create_nav_menu($menu_name);
    785807
    786808            // Add menu items.
     
    789811                0,
    790812                array(
    791                     'menu-item-title'  => esc_html__( 'Home', 'elevation-blocks' ),
    792                     'menu-item-url'    => home_url( '/' ),
     813                    'menu-item-title'  => esc_html__('Home', 'elevation-blocks'),
     814                    'menu-item-url'    => home_url('/'),
    793815                    'menu-item-status' => 'publish',
    794816                )
     
    799821                0,
    800822                array(
    801                     'menu-item-title'  => esc_html__( 'About', 'elevation-blocks' ),
    802                     'menu-item-url'    => home_url( '/about/' ),
     823                    'menu-item-title'  => esc_html__('About', 'elevation-blocks'),
     824                    'menu-item-url'    => home_url('/about/'),
    803825                    'menu-item-status' => 'publish',
    804826                )
     
    809831                0,
    810832                array(
    811                     'menu-item-title'  => esc_html__( 'Contact', 'elevation-blocks' ),
    812                     'menu-item-url'    => home_url( '/contact/' ),
     833                    'menu-item-title'  => esc_html__('Contact', 'elevation-blocks'),
     834                    'menu-item-url'    => home_url('/contact/'),
    813835                    'menu-item-status' => 'publish',
    814836                )
     
    816838
    817839            // Assign menu to a theme location (update with your theme location).
    818             $locations           = get_theme_mod( 'nav_menu_locations' );
     840            $locations           = get_theme_mod('nav_menu_locations');
    819841            $locations['menu-1'] = $menu_id; // Change 'menu-1' to the correct theme location.
    820             set_theme_mod( 'nav_menu_locations', $locations );
     842            set_theme_mod('nav_menu_locations', $locations);
    821843        }
    822844    }
     
    827849     * @return object
    828850     */
    829     public static function instance() {
    830         if ( is_null( self::$instance ) ) {
     851    public static function instance()
     852    {
     853        if (is_null(self::$instance)) {
    831854            self::$instance = new self();
    832855        }
  • elevation-blocks/trunk/lib/admin/controls/class-helpers.php

    r3313416 r3313497  
    11<?php
     2
    23/**
    34 * File Name: class-helpers.php
     
    1011namespace ElevationBlocks\Lib\Admin\Controls;
    1112
    12 if ( ! defined( 'ABSPATH' ) ) {
     13if (! defined('ABSPATH')) {
    1314    exit;
    1415}
     
    1718 * Class Helpers
    1819 */
    19 class Helpers {
     20class Helpers
     21{
    2022
    2123
     
    3234     * @return void
    3335     */
    34     public function __construct() {
    35         add_action( 'admin_menu', array( $this, 'elevation_blocks_import_admin_menu' ) );
     36    public function __construct()
     37    {
     38        add_action('admin_menu', array($this, 'elevation_blocks_import_admin_menu'));
    3639    }
    3740
     
    4144     * @return html
    4245     */
    43     public function elevation_blocks_import_page_html() {
    44         if ( ! current_user_can( 'manage_options' ) ) {
     46    public function elevation_blocks_import_page_html()
     47    {
     48        if (! current_user_can('manage_options')) {
    4549            return;
    4650        }
    4751
    4852        // Handle import action.
    49         if ( isset( $_POST['import_demo_content'] ) ) {
     53        if (isset($_POST['import_demo_content'])) {
    5054            // Unslash the data before verification.
    51             $import_demo_nonce = isset( $_POST['import_demo_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['import_demo_nonce'] ) ) : '';
     55            $import_demo_nonce = isset($_POST['import_demo_nonce']) ? sanitize_text_field(wp_unslash($_POST['import_demo_nonce'])) : '';
    5256
    5357            // Verify the nonce after unslashing.
    54             if ( ! wp_verify_nonce( $import_demo_nonce, 'import_demo_nonce_action' ) ) {
    55                 wp_die( esc_html__( 'Nonce verification failed', 'elevation-blocks' ) );
     58            if (! wp_verify_nonce($import_demo_nonce, 'import_demo_nonce_action')) {
     59                wp_die(esc_html__('Nonce verification failed', 'elevation-blocks'));
    5660            }
    5761
     
    6468        }
    6569
    66         ?>
     70?>
    6771        <div class="wrap">
    68             <h1><?php echo esc_html__( 'Import Elevation Demo Content', 'elevation-blocks' ); ?></h1>
    69             <p><?php echo esc_html__( 'Click the button below to import default pages for your theme.', 'elevation-blocks' ); ?></p>
     72            <h1><?php echo esc_html__('Import Elevation Demo Content', 'elevation-blocks'); ?></h1>
     73            <p><?php echo esc_html__('Click the button below to import default pages for your theme.', 'elevation-blocks'); ?></p>
    7074            <form method="post">
    71                 <?php wp_nonce_field( 'import_demo_nonce_action', 'import_demo_nonce' ); ?>
    72                 <input type="submit" name="import_demo_content" class="button button-primary" value="<?php echo esc_attr__( 'Import Pages', 'elevation-blocks' ); ?>" onclick="return confirm('Are you sure you want to import demo content? This could overwrite existing content.');">
     75                <?php wp_nonce_field('import_demo_nonce_action', 'import_demo_nonce'); ?>
     76                <input type="submit" name="import_demo_content" class="button button-primary" value="<?php echo esc_attr__('Import Pages', 'elevation-blocks'); ?>" onclick="return confirm('Are you sure you want to import demo content? This could overwrite existing content.');">
    7377            </form>
    7478        </div>
    75         <?php
     79<?php
    7680    }
    7781
     
    8185     * @return void
    8286     */
    83     public function elevation_blocks_import_admin_menu() {
     87    public function elevation_blocks_import_admin_menu()
     88    {
    8489        add_management_page(
    85             esc_html__( 'Import Elevation Demo Content', 'elevation-blocks' ), // Page title.
    86             esc_html__( 'Import Elevation Demo Content', 'elevation-blocks' ),      // Menu title.
     90            esc_html__('Import Elevation Demo Content', 'elevation-blocks'), // Page title.
     91            esc_html__('Import Elevation Demo Content', 'elevation-blocks'),      // Menu title.
    8792            'manage_options',      // Capability.
    8893            'elevation-import',      // Menu slug.
    89             array( $this, 'elevation_blocks_import_page_html' ), // Callback function.
     94            array($this, 'elevation_blocks_import_page_html'), // Callback function.
    9095        );
    9196    }
     
    96101     * @return void
    97102     */
    98     public function elevation_blocks_import_demo_pages() {
     103    public function elevation_blocks_import_demo_pages()
     104    {
    99105        // Define the paths to the images.
    100106        $image_paths = array(
    101             'home-banner'         => plugin_dir_url( __DIR__ ) . 'assets/matthew-henry-2Ts5HnA67k8-unsplash.avif',
    102             'home-second-section' => plugin_dir_url( __DIR__ ) . 'assets/matthew-henry-U5rMrSI7Pn4-unsplash.avif',
    103             'about-banner'        => plugin_dir_url( __DIR__ ) . 'assets/paulo-simoes-mendes-V8YzvXKLwDw-unsplash.avif',
    104             'contact-banner'      => plugin_dir_url( __DIR__ ) . 'assets/samantha-sophia-NaWKMlp3tVs-unsplash.avif',
     107            'home-banner'         => ELEVATION_BLOCKS_DIR . 'assets/matthew-henry-2Ts5HnA67k8-unsplash.avif',
     108            'home-second-section' => ELEVATION_BLOCKS_DIR . 'assets/matthew-henry-U5rMrSI7Pn4-unsplash.avif',
     109            'about-banner'        => ELEVATION_BLOCKS_DIR . 'assets/paulo-simoes-mendes-V8YzvXKLwDw-unsplash.avif',
     110            'contact-banner'      => ELEVATION_BLOCKS_DIR . 'assets/samantha-sophia-NaWKMlp3tVs-unsplash.avif',
    105111        );
    106112
     113
    107114        $uploaded_images = array();
    108         foreach ( $image_paths as $key => $image_path ) {
    109             $uploaded_images[ $key ] = $this->elevation_blocks_upload_image( $image_path );
     115        foreach ($image_paths as $key => $image_path) {
     116            $uploaded_images[$key] = $this->elevation_blocks_upload_image($image_path);
    110117        }
    111118
     
    113120            array(
    114121                'title'   => 'Home',
    115                 'content' => $this->elevation_blocks_home_page( $uploaded_images ),
     122                'content' => $this->elevation_blocks_home_page($uploaded_images),
    116123            ),
    117124            array(
    118125                'title'   => 'About',
    119                 'content' => $this->elevation_blocks_about_page( $uploaded_images ),
     126                'content' => $this->elevation_blocks_about_page($uploaded_images),
    120127            ),
    121128            array(
    122129                'title'   => 'Contact',
    123                 'content' => $this->elevation_blocks_contact_page( $uploaded_images ),
     130                'content' => $this->elevation_blocks_contact_page($uploaded_images),
    124131            ),
    125132        );
    126133
    127         foreach ( $default_pages as $page ) {
     134        foreach ($default_pages as $page) {
    128135            // Check if the page already exists.
    129136            $page_query = new \WP_Query(
     
    138145            $existing_page = $page_query->have_posts();
    139146
    140             if ( ! $existing_page ) {
     147            if (! $existing_page) {
    141148                $page_id = wp_insert_post(
    142149                    array(
     
    148155                );
    149156
    150                 if ( 'Home' === $page['title'] ) {
    151                     update_option( 'show_on_front', 'page' ); // Set static page mode.
    152                     update_option( 'page_on_front', $page_id ); // Set the front page.
     157                if ('Home' === $page['title']) {
     158                    update_option('show_on_front', 'page'); // Set static page mode.
     159                    update_option('page_on_front', $page_id); // Set the front page.
    153160                }
    154161            }
     
    163170     * @return array
    164171     */
    165     private function elevation_blocks_upload_image( $file_path ) {
    166         if ( ! file_exists( $file_path ) ) {
     172    private function elevation_blocks_upload_image($file_path)
     173    {
     174        if (! file_exists($file_path)) {
    167175            return false;
    168176        }
    169177
    170         $file_name     = basename( $file_path );
     178        $file_name     = basename($file_path);
    171179        $upload_dir    = wp_upload_dir();
    172180        $new_file_path = $upload_dir['path'] . '/' . $file_name;
    173181
    174         if ( ! copy( $file_path, $new_file_path ) ) {
     182        if (! copy($file_path, $new_file_path)) {
    175183            return false;
    176184        }
    177185
    178         $file_type  = wp_check_filetype( $new_file_path, null );
     186        $file_type  = wp_check_filetype($new_file_path, null);
    179187        $attachment = array(
    180188            'post_mime_type' => $file_type['type'],
    181             'post_title'     => sanitize_file_name( $file_name ),
     189            'post_title'     => sanitize_file_name($file_name),
    182190            'post_content'   => '',
    183191            'post_status'    => 'inherit',
    184192        );
    185193
    186         $attach_id = wp_insert_attachment( $attachment, $new_file_path );
     194        $attach_id = wp_insert_attachment($attachment, $new_file_path);
    187195        require_once ABSPATH . 'wp-admin/includes/image.php';
    188         $attach_data = wp_generate_attachment_metadata( $attach_id, $new_file_path );
    189         wp_update_attachment_metadata( $attach_id, $attach_data );
    190 
    191         return array( $attach_id, wp_get_attachment_url( $attach_id ) ); // Return the image URL.
     196        $attach_data = wp_generate_attachment_metadata($attach_id, $new_file_path);
     197        wp_update_attachment_metadata($attach_id, $attach_data);
     198
     199        return array($attach_id, wp_get_attachment_url($attach_id)); // Return the image URL.
    192200    }
    193201
     
    199207     * @return array
    200208     */
    201     private function elevation_blocks_upload_image_from_url( $image_url ) {
    202         if ( ! filter_var( $image_url, FILTER_VALIDATE_URL ) ) {
     209    private function elevation_blocks_upload_image_from_url($image_url)
     210    {
     211
     212        if (! filter_var($image_url, FILTER_VALIDATE_URL)) {
    203213            return false;
    204214        }
    205215
    206216        // Get file contents.
    207         $response = wp_remote_get( $image_url );
    208 
    209         if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
     217        $response = wp_remote_get($image_url);
     218
     219
     220
     221        if (is_wp_error($response) || 200 !== wp_remote_retrieve_response_code($response)) {
    210222            return false;
    211223        }
    212224
    213         $image_data = wp_remote_retrieve_body( $response );
    214         if ( empty( $image_data ) ) {
     225        $image_data = wp_remote_retrieve_body($response);
     226        if (empty($image_data)) {
    215227            return false;
    216228        }
    217229
    218230        // Extract filename from URL.
    219         $file_name = basename( wp_parse_url( $image_url, PHP_URL_PATH ) );
     231        $file_name = basename(wp_parse_url($image_url, PHP_URL_PATH));
    220232
    221233        // Get upload directory.
    222234        $upload_dir    = wp_upload_dir();
    223         $new_file_path = trailingslashit( $upload_dir['path'] ) . $file_name;
     235        $new_file_path = trailingslashit($upload_dir['path']) . $file_name;
    224236
    225237        // Use WP_Filesystem to save the file.
     
    229241        WP_Filesystem();
    230242
    231         if ( ! $wp_filesystem->put_contents( $new_file_path, $image_data, FS_CHMOD_FILE ) ) {
     243        if (! $wp_filesystem->put_contents($new_file_path, $image_data, FS_CHMOD_FILE)) {
    232244            return false;
    233245        }
    234246
    235247        // Get file type.
    236         $file_type = wp_check_filetype( $file_name, null );
     248        $file_type = wp_check_filetype($file_name, null);
    237249
    238250        // Create attachment.
    239251        $attachment = array(
    240252            'post_mime_type' => $file_type['type'],
    241             'post_title'     => sanitize_file_name( $file_name ),
     253            'post_title'     => sanitize_file_name($file_name),
    242254            'post_content'   => '',
    243255            'post_status'    => 'inherit',
    244256        );
    245257
    246         $attach_id = wp_insert_attachment( $attachment, $new_file_path );
     258        $attach_id = wp_insert_attachment($attachment, $new_file_path);
     259
     260
    247261        require_once ABSPATH . 'wp-admin/includes/image.php';
    248         $attach_data = wp_generate_attachment_metadata( $attach_id, $new_file_path );
    249         wp_update_attachment_metadata( $attach_id, $attach_data );
    250 
    251         return array( $attach_id, wp_get_attachment_url( $attach_id ) ); // Return the image URL.
     262        $attach_data = wp_generate_attachment_metadata($attach_id, $new_file_path);
     263        wp_update_attachment_metadata($attach_id, $attach_data);
     264
     265        return array($attach_id, wp_get_attachment_url($attach_id)); // Return the image URL.
    252266    }
    253267
     
    263277     * @return string
    264278     */
    265     private function elevation_blocks_home_page( $uploaded_images ) {
    266         if ( empty( $uploaded_images['home-banner'] ) || empty( $uploaded_images['home-second-section'] ) ) {
     279    private function elevation_blocks_home_page($uploaded_images)
     280    {
     281        if (empty($uploaded_images['home-banner']) || empty($uploaded_images['home-second-section'])) {
    267282            return '';
    268283        }
     
    394409     * @return string
    395410     */
    396     private function elevation_blocks_about_page( $uploaded_images ) {
    397         if ( empty( $uploaded_images['about-banner'] ) ) {
     411    private function elevation_blocks_about_page($uploaded_images)
     412    {
     413        if (empty($uploaded_images['about-banner'])) {
    398414            return '';
    399415        }
     
    535551     * @return string
    536552     */
    537     private function elevation_blocks_contact_page( $uploaded_images ) {
    538         if ( empty( $uploaded_images['contact-banner'] ) ) {
     553    private function elevation_blocks_contact_page($uploaded_images)
     554    {
     555        if (empty($uploaded_images['contact-banner'])) {
    539556            return '';
    540557        }
     
    662679     * @return void
    663680     */
    664     public function elevation_blocks_add_default_widgets_to_sidebars() {
     681    public function elevation_blocks_add_default_widgets_to_sidebars()
     682    {
    665683        $this->elevation_blocks_update_option_wiget_block();
    666684        $this->elevation_blocks_update_option_sidebar_widgets();
     
    672690     * @return void
    673691     */
    674     public function elevation_blocks_update_option_wiget_block() {
     692    public function elevation_blocks_update_option_wiget_block()
     693    {
    675694        $content_2 = preg_replace(
    676695            '/\s+/',
     
    725744        );
    726745
    727         update_option( 'elevation_blocks_widget_block', $widget_block );
     746        update_option('elevation_blocks_widget_block', $widget_block);
    728747    }
    729748
     
    733752     * @return void
    734753     */
    735     public function elevation_blocks_update_option_sidebar_widgets() {
     754    public function elevation_blocks_update_option_sidebar_widgets()
     755    {
    736756        $sidebar_widgets = array(
    737757            'wp_inactive_widgets' =>
     
    750770        );
    751771
    752         update_option( 'elevation_blocks_sidebar_widgets', $sidebar_widgets );
     772        update_option('elevation_blocks_sidebar_widgets', $sidebar_widgets);
    753773    }
    754774
     
    758778     * @return void
    759779     */
    760     private function elevation_blocks_set_custom_image() {
     780    private function elevation_blocks_set_custom_image()
     781    {
    761782        // Define the image URL.
    762783        $header_image_url = ELEVATION_BLOCKS_DIR_URL . '/lib/admin/controls/images/logo-elevation.webp';
     
    764785
    765786        // Set the image URL programmatically in the customizer.
    766         set_theme_mod( 'custom_logo', $header_image_url );
    767         set_theme_mod( 'footer_logo', $footer_image_url );
     787        set_theme_mod('custom_logo', $header_image_url);
     788        set_theme_mod('footer_logo', $footer_image_url);
    768789    }
    769790
     
    773794     * @return void
    774795     */
    775     public function elevation_blocks_create_custom_menu() {
     796    public function elevation_blocks_create_custom_menu()
     797    {
    776798        // Define the menu name.
    777799        $menu_name = 'Main Menu';
    778800
    779801        // Check if the menu already exists.
    780         $menu_exists = wp_get_nav_menu_object( $menu_name );
     802        $menu_exists = wp_get_nav_menu_object($menu_name);
    781803
    782804        // Create menu if it doesn't exist.
    783         if ( ! $menu_exists ) {
    784             $menu_id = wp_create_nav_menu( $menu_name );
     805        if (! $menu_exists) {
     806            $menu_id = wp_create_nav_menu($menu_name);
    785807
    786808            // Add menu items.
     
    789811                0,
    790812                array(
    791                     'menu-item-title'  => esc_html__( 'Home', 'elevation-blocks' ),
    792                     'menu-item-url'    => home_url( '/' ),
     813                    'menu-item-title'  => esc_html__('Home', 'elevation-blocks'),
     814                    'menu-item-url'    => home_url('/'),
    793815                    'menu-item-status' => 'publish',
    794816                )
     
    799821                0,
    800822                array(
    801                     'menu-item-title'  => esc_html__( 'About', 'elevation-blocks' ),
    802                     'menu-item-url'    => home_url( '/about/' ),
     823                    'menu-item-title'  => esc_html__('About', 'elevation-blocks'),
     824                    'menu-item-url'    => home_url('/about/'),
    803825                    'menu-item-status' => 'publish',
    804826                )
     
    809831                0,
    810832                array(
    811                     'menu-item-title'  => esc_html__( 'Contact', 'elevation-blocks' ),
    812                     'menu-item-url'    => home_url( '/contact/' ),
     833                    'menu-item-title'  => esc_html__('Contact', 'elevation-blocks'),
     834                    'menu-item-url'    => home_url('/contact/'),
    813835                    'menu-item-status' => 'publish',
    814836                )
     
    816838
    817839            // Assign menu to a theme location (update with your theme location).
    818             $locations           = get_theme_mod( 'nav_menu_locations' );
     840            $locations           = get_theme_mod('nav_menu_locations');
    819841            $locations['menu-1'] = $menu_id; // Change 'menu-1' to the correct theme location.
    820             set_theme_mod( 'nav_menu_locations', $locations );
     842            set_theme_mod('nav_menu_locations', $locations);
    821843        }
    822844    }
     
    827849     * @return object
    828850     */
    829     public static function instance() {
    830         if ( is_null( self::$instance ) ) {
     851    public static function instance()
     852    {
     853        if (is_null(self::$instance)) {
    831854            self::$instance = new self();
    832855        }
Note: See TracChangeset for help on using the changeset viewer.