Plugin Directory

Changeset 3438430


Ignore:
Timestamp:
01/13/2026 09:17:37 AM (2 months ago)
Author:
iflairwebtechnologies
Message:

Fixed hardcoded paths and URLs; moved service worker, register JS, and manifest files to uploads folder for WordPress.org compliance; added Filesystem fallback; updated status checker.

Location:
iflair-pwa-app
Files:
32 added
5 edited

Legend:

Unmodified
Added
Removed
  • iflair-pwa-app/trunk/iflair-pwa-app.php

    r3433592 r3438430  
    44Description: SiteEase Progressive Web App plugin transforms your website into a Progressive Web App (PWA), enhancing user experience with app-like features such as faster load times, offline accessibility, and the convenience of adding the site to a smartphone's home screen. It also offers customizable backend settings, allowing for modifications to the app's color, name, and more, ensuring a personalized and seamless integration.
    55Plugin URI: https://profiles.wordpress.org/iflairwebtechnologies
    6 Version: 1.1.4
     6Version: 1.1.5
    77Author: iFlair Web Technologies Pvt. Ltd.
    88Author URI: https://www.iflair.com/
     
    1414if ( ! defined( 'ABSPATH' ) ) { die(); }
    1515// define plugin version
    16 define( 'IFPWAP_VERSION' , '1.1.4' );
     16define( 'IFPWAP_VERSION' , '1.1.5' );
    1717define( 'IFPWAP_FILE', __FILE__ );
    1818define( 'IFPWAP_DIR', dirname(__FILE__));
    19 define( 'IFPWAP_DIR_PATH', plugin_dir_url( __FILE__ ) );
     19
     20define( 'IFPWAP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
     21define( 'IFPWAP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
    2022
    2123$ifpwap_version = IFPWAP_VERSION;
     
    7981   return $links;
    8082}
    81 // Enqueue admin JS
    82 add_action( 'admin_enqueue_scripts', 'ifpwap_include_js' );
    83 function ifpwap_include_js() {
    84     wp_enqueue_script('jquery');
    85     // WordPress media uploader scripts
    86     if ( ! did_action( 'wp_enqueue_media' ) ) { wp_enqueue_media(); }
    87     wp_enqueue_script('ifpwap-custom-js',plugin_dir_url( __FILE__ ). 'assets/admin/js/custom.js',array( 'wp-color-picker' ), false, true);
    88 }
    89 // Enqueue admin CSS
    90 add_action( 'admin_enqueue_scripts', 'ifpwap_enqueue_color_picker' );
    91 function ifpwap_enqueue_color_picker( $hook_suffix ) {
    92     wp_enqueue_style( 'wp-color-picker' );
    93     wp_enqueue_style( 'dashicons' );
    94     wp_enqueue_style( 'ifpwap-style', plugins_url( '/assets/admin/css/style.css', __FILE__ ), '', IFPWAP_VERSION );
    95 }
     83
     84// Enqueue admin script
     85function ifpwap_enqueue_admin_assets( $hook_suffix ) {
     86    // Load assets only on plugin admin pages (recommended)
     87    if ( strpos( $hook_suffix, 'ifpwap' ) === false ) {
     88        return;
     89    }
     90    // Media uploader (safe to call directly)
     91    wp_enqueue_media();
     92    // Admin CSS
     93    wp_enqueue_style(
     94        'ifpwap-admin-style',
     95        IFPWAP_PLUGIN_URL . 'assets/admin/css/style.css',
     96        array( 'wp-color-picker', 'dashicons' ),
     97        IFPWAP_VERSION
     98    );
     99    // Admin JS
     100    wp_enqueue_script(
     101        'ifpwap-admin-js',
     102        IFPWAP_PLUGIN_URL . 'assets/admin/js/custom.js',
     103        array( 'jquery', 'wp-color-picker' ),
     104        IFPWAP_VERSION,
     105        true
     106    );
     107}
     108add_action( 'admin_enqueue_scripts', 'ifpwap_enqueue_admin_assets' );
    96109
    97110// Inside your plugin file or theme's functions.php file
    98111function ifpwap_enqueue_install_prompt_script() {
    99     wp_enqueue_script('jquery');
    100     // Ensure the URLs are from a secure source and properly formatted
    101     $font_awesome_url = esc_url( plugins_url('assets/frontend/font-awesome.css', __FILE__) );
    102     $style_url = esc_url( plugins_url('assets/frontend/style.css', __FILE__) );
    103     wp_enqueue_style('ifpwap-font-awesome-style', $font_awesome_url);
    104     wp_enqueue_style('ifpwap-style', $style_url);
    105 }
    106 add_action('wp_enqueue_scripts', 'ifpwap_enqueue_install_prompt_script');
     112    wp_enqueue_style(
     113        'ifpwap-font-awesome-style',
     114        IFPWAP_PLUGIN_URL . 'assets/frontend/font-awesome.css',
     115        array(),
     116        IFPWAP_VERSION
     117    );
     118    wp_enqueue_style(
     119        'ifpwap-style',
     120        IFPWAP_PLUGIN_URL . 'assets/frontend/style.css',
     121        array(),
     122        IFPWAP_VERSION
     123    );
     124}
     125add_action( 'wp_enqueue_scripts', 'ifpwap_enqueue_install_prompt_script' );
    107126
    108127// default options values added while plugin active
     
    126145add_action( 'wp_head', 'ifpwap_inc_manifest_link' );
    127146function ifpwap_inc_manifest_link() { 
    128     $ifpwap_theme_color = get_option('ifpwap_theme_color');
     147    $ifpwap_theme_color = get_option( 'ifpwap_theme_color', '#ffffff' );
    129148    ?>
    130149    <meta name="theme-color" content="<?php echo esc_attr($ifpwap_theme_color);?>">
     
    132151}
    133152
    134 add_action( 'wp_enqueue_scripts', 'ifpwap_enqueue_manifest_link' );
    135 function ifpwap_enqueue_manifest_link() { 
    136     // Get the URL for the manifest file
    137     $manifest_url = esc_url( get_site_url() . '/ifpwap-manifest.json' );
    138     // Enqueue the manifest file as a style
    139     wp_enqueue_style( 'ifpwap-manifest', $manifest_url, array(), null );
    140 }
     153function ifpwap_add_manifest_link() {
     154    $manifest_url = home_url( '/ifpwap-manifest.json' );
     155    ?>
     156    <link rel="manifest" href="<?php echo esc_url( $manifest_url ); ?>">
     157    <?php
     158}
     159add_action( 'wp_head', 'ifpwap_add_manifest_link' );
     160
    141161add_filter( 'style_loader_tag', 'ifpwap_modify_manifest_link_tag', 10, 4 );
    142162function ifpwap_modify_manifest_link_tag( $html, $handle, $href, $media ) {
     
    147167}
    148168
    149 add_action( 'wp_enqueue_scripts', 'ifpwap_enqueue_prefetch_manifest_link' );
    150 function ifpwap_enqueue_prefetch_manifest_link() { 
    151     // Get the URL for the manifest file
    152     $manifest_url = esc_url( get_site_url() . '/ifpwap-manifest.json' );
    153     // Enqueue the prefetch link
    154     wp_enqueue_script( 'ifpwap-prefetch-manifest', $manifest_url, array(), null, true );
    155 }
    156169add_filter( 'script_loader_tag', 'ifpwap_modify_prefetch_manifest_link_tag', 10, 3 );
    157170function ifpwap_modify_prefetch_manifest_link_tag( $tag, $handle, $src ) {
     
    163176
    164177// Register JS files in footer
    165 add_action('wp_enqueue_scripts', 'ifpwap_register_footer_js');
    166178function ifpwap_register_footer_js() {
    167     wp_enqueue_script('ifpwap-footer-js', esc_url(get_site_url().'/ifpwap-register-sw.js'), array(), null, true);
    168 }
     179    wp_enqueue_script(
     180        'ifpwap-footer-js',
     181        home_url( '/ifpwap-register-sw.js' ),
     182        array(),
     183        IFPWAP_VERSION,
     184        true
     185    );
     186}
     187add_action( 'wp_enqueue_scripts', 'ifpwap_register_footer_js' );
    169188
    170189function ifpwap_common_sanitize($input) {
     
    272291// Remove the trailing comma after the last iteration
    273292$ifpwap_start_page_name = get_the_title($ifpwap_select_start_page);
    274 $base = plugin_dir_path(__FILE__);
    275 $root_path = plugin_dir_path(dirname(dirname($base)));
     293// $base = plugin_dir_path(__FILE__);
     294// $root_path = plugin_dir_path(dirname(dirname($base)));
     295$root_path = IFPWAP_PLUGIN_DIR;
    276296
    277297$offline_page_slug = get_post_field( 'post_name', $ifpwap_select_offline_page );
     
    289309// Check if the current page is the front page
    290310if ( ! is_front_page() ) {
    291 
    292311    // Get front page ID and title
    293312    $front_page_id    = (int) get_option( 'page_on_front' );
    294313    $front_page_title = $front_page_id ? get_the_title( $front_page_id ) : '';
    295 
    296314    if ( ! empty( $ifpwap_start_page_name ) && $ifpwap_start_page_name !== $front_page_title ) {
    297 
    298315        // Fetch page by title (replacement for deprecated get_page_by_title)
    299316        $pages = get_posts( [
     
    375392);
    376393$ifpwap_manifest_json = json_encode($ifpwap_manifest_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
    377 if ($wp_filesystem) {
    378     $manifest_fp = trailingslashit($root_path) . "ifpwap-manifest.json";
    379     if (false === $wp_filesystem->put_contents($manifest_fp, $ifpwap_manifest_json, FS_CHMOD_FILE)) {
    380         echo esc_html__('Failed to write the manifest file.', 'iflair-pwa-app');
     394// Use the uploads directory instead of plugin folder
     395$upload_dir = wp_upload_dir();
     396$plugin_upload_dir = trailingslashit( $upload_dir['basedir'] ) . 'iflair-pwa-app/';
     397
     398// Make sure the folder exists
     399if ( ! file_exists( $plugin_upload_dir ) ) {
     400    wp_mkdir_p( $plugin_upload_dir );
     401}
     402
     403// Full file path
     404$manifest_fp = $plugin_upload_dir . 'ifpwap-manifest.json';
     405
     406// Write file using WP_Filesystem if available, fallback to PHP file_put_contents
     407if ( $wp_filesystem ) {
     408    if ( false === $wp_filesystem->put_contents( $manifest_fp, $ifpwap_manifest_json, FS_CHMOD_FILE ) ) {
     409        echo esc_html__( 'Failed to write the manifest file.', 'iflair-pwa-app' );
    381410    }
    382411} else {
    383     echo esc_html__('Filesystem API not initialized.', 'iflair-pwa-app');
     412    if ( false === file_put_contents( $manifest_fp, $ifpwap_manifest_json ) ) {
     413        echo esc_html__( 'Failed to write the manifest file.', 'iflair-pwa-app' );
     414    }
    384415}
    385416
     
    427458    }
    428459});";
    429 if ($wp_filesystem) {
    430     $registersw_fp = trailingslashit($root_path) . "ifpwap-register-sw.js"; // Ensure path is correctly formatted
     460
     461// Use uploads folder instead of plugin folder
     462$upload_dir = wp_upload_dir();
     463$plugin_upload_dir = trailingslashit( $upload_dir['basedir'] ) . 'iflair-pwa-app/';
     464
     465// Make sure the folder exists
     466if ( ! file_exists( $plugin_upload_dir ) ) {
     467    wp_mkdir_p( $plugin_upload_dir );
     468}
     469
     470// Full file path
     471$registersw_fp = $plugin_upload_dir . 'ifpwap-register-sw.js';
     472
     473// Write file using WP_Filesystem if available, fallback to PHP file_put_contents
     474if ( $wp_filesystem ) {
    431475    $success = $wp_filesystem->put_contents(
    432476        $registersw_fp,
    433477        $ifpwap_register_service_worker_js,
    434         FS_CHMOD_FILE // Set proper file permissions
    435     );
    436     if (!$success) {
    437         echo esc_html__('Failed to write the service worker file.', 'iflair-pwa-app');
     478        FS_CHMOD_FILE
     479    );
     480
     481    if ( ! $success ) {
     482        echo esc_html__( 'Failed to write the service worker file.', 'iflair-pwa-app' );
    438483    }
    439484} else {
    440     echo esc_html__('Filesystem API not initialized.', 'iflair-pwa-app');
    441 }
     485    if ( false === file_put_contents( $registersw_fp, $ifpwap_register_service_worker_js ) ) {
     486        echo esc_html__( 'Failed to write the service worker file.', 'iflair-pwa-app' );
     487    }
     488}
     489
    442490// analytics js code for append
    443491$ifpwap_analytics_js_append = "importScripts(\"https://storage.googleapis.com/workbox-cdn/releases/6.0.2/workbox-sw.js\");
     
    467515// End get manual cache URLs code
    468516$ifpwap_cache_external_urls = get_option('ifpwap_cache_external_urls');
     517$ifpwap_external_url_cache_js = '';
    469518if($ifpwap_cache_external_urls == 'yes'){
    470519    $ifpwap_external_url_cache_js = $ifpwap_external_url_cache_js_append;
     
    667716}";
    668717// Append analytics code if enabled
    669 if ($ifpwap_offline_analytics == 'yes') {
     718if ( $ifpwap_offline_analytics === 'yes' ) {
    670719    $ifpwap_final_sw_js = $ifpwap_sw_js . "\n" . $ifpwap_analytics_js_append;
    671720} else {
    672721    $ifpwap_final_sw_js = $ifpwap_sw_js;
    673722}
     723
     724// Get the plugin upload directory
     725$upload_dir = wp_upload_dir();
     726$plugin_upload_dir = trailingslashit( $upload_dir['basedir'] ) . 'iflair-pwa-app/';
     727
     728// Make sure the folder exists
     729if ( ! file_exists( $plugin_upload_dir ) ) {
     730    wp_mkdir_p( $plugin_upload_dir );
     731}
     732
     733// Full file path
     734$sw_fp = $plugin_upload_dir . 'ifpwap-sw.js';
     735
     736// Write file using WP_Filesystem if available, fallback to PHP file_put_contents
    674737if ( $wp_filesystem ) {
    675     $sw_fp = trailingslashit($root_path) . "ifpwap-sw.js"; // Ensure path is correctly formatted
    676738    $success = $wp_filesystem->put_contents(
    677739        $sw_fp,
    678740        $ifpwap_final_sw_js,
    679         FS_CHMOD_FILE // Set proper file permissions
    680     );
    681     if (!$success) {
    682         echo esc_html__('Failed to write the service worker file.', 'iflair-pwa-app');
     741        FS_CHMOD_FILE
     742    );
     743
     744    if ( ! $success ) {
     745        echo esc_html__( 'Failed to write the service worker file.', 'iflair-pwa-app' );
    683746    }
    684747} else {
    685     echo esc_html__('Filesystem API not initialized.', 'iflair-pwa-app');
     748    if ( false === file_put_contents( $sw_fp, $ifpwap_final_sw_js ) ) {
     749        echo esc_html__( 'Failed to write the service worker file.', 'iflair-pwa-app' );
     750    }
    686751}
    687752
     
    802867// Action hook to execute the code within the WordPress environment
    803868function ifpwap_check_files_and_https_status() {
    804     // Check if WordPress environment is loaded
    805     if (function_exists('get_site_url')) {
    806         // Specify the files to check
    807         $files_to_check = array(
    808             'ifpwap-sw.js',
    809             'ifpwap-register-sw.js',
    810             'ifpwap-manifest.json'
    811         );
    812         // Initialize array to store file URLs
    813         $file_urls = array();
    814         // Check if files exist and get their URLs
    815         foreach ($files_to_check as $file) {
    816             $file_path = ABSPATH . $file;
    817             if (file_exists($file_path)) {
    818                 $file_urls[$file] = get_site_url(null, '/' . $file);
    819             }
     869    // Get plugin uploads directory
     870    $upload_dir = wp_upload_dir();
     871    $plugin_upload_dir = trailingslashit( $upload_dir['basedir'] ) . 'iflair-pwa-app/';
     872    $plugin_upload_url = trailingslashit( $upload_dir['baseurl'] ) . 'iflair-pwa-app/';
     873
     874    $files_to_check = array(
     875        'ifpwap-sw.js',
     876        'ifpwap-register-sw.js',
     877        'ifpwap-manifest.json'
     878    );
     879
     880    $file_urls = array();
     881
     882    foreach ( $files_to_check as $file ) {
     883        $file_path = $plugin_upload_dir . $file; // Check in uploads folder
     884        if ( file_exists( $file_path ) ) {
     885            $file_urls[ $file ] = $plugin_upload_url . $file; // URL from uploads folder
    820886        }
    821         // Check if website is served over HTTPS
    822         $https_status = (is_ssl()) ? 'Yes' : 'No';
    823         // Output HTML with file URLs and HTTPS status
    824         ?>       
    825         <div class="ifpwap_files_url">
    826             <h3><?php echo esc_html__('Status','iflair-pwa-app');?></h3>
    827             <?php
    828             foreach ($file_urls as $file => $url) { ?>
    829                 <p class='ifpwap_<?php echo esc_attr($file);?>'><a class='ifpwap_icon-link' target='_blank' href='<?php echo esc_url($url);?>'><?php echo esc_html($file);?></a><?php echo esc_html__(' File successfully generated.','iflair-pwa-app');?></p>
    830             <?php } ?>
    831             <p class='ifpwap_https ifpwap_icon-link'><?php echo esc_html__('Website served over HTTPS:','iflair-pwa-app') . ' ' . esc_html($https_status);?></p>
    832         </div>
    833     <?php } else {
    834         echo esc_html__('WordPress environment not found.','iflair-pwa-app');
    835     }
    836 }
     887    }
     888
     889    $https_status = is_ssl() ? 'Yes' : 'No';
     890    ?>
     891
     892    <div class="ifpwap_files_url">
     893        <h3><?php echo esc_html__( 'Status', 'iflair-pwa-app' ); ?></h3>
     894        <?php foreach ( $file_urls as $file => $url ) : ?>
     895            <p class="ifpwap_<?php echo esc_attr( $file ); ?>">
     896                <a class="ifpwap_icon-link" target="_blank" href="<?php echo esc_url( $url ); ?>">
     897                    <?php echo esc_html( $file ); ?>
     898                </a>
     899                <?php echo esc_html__( ' File successfully generated.', 'iflair-pwa-app' ); ?>
     900            </p>
     901        <?php endforeach; ?>
     902        <p class="ifpwap_https ifpwap_icon-link">
     903            <?php
     904            echo esc_html__( 'Website served over HTTPS:', 'iflair-pwa-app' ) . ' ' . esc_html( $https_status );
     905            ?>
     906        </p>
     907    </div>
     908    <?php
     909}
  • iflair-pwa-app/trunk/includes/admin/advanced.php

    r3433574 r3438430  
    66$ifpwap_cache_external_urls = get_option('ifpwap_cache_external_urls');
    77$ifpwap_exclude_urls_from_cache_list = get_option('ifpwap_exclude_urls_from_cache_list');
    8 $ifpwap_tooltip_url = plugins_url().'/iflair-pwa-app/assets/admin/images/tooltip_icon.png';
     8// $ifpwap_tooltip_url = plugins_url().'/iflair-pwa-app/assets/admin/images/tooltip_icon.png';
     9$ifpwap_tooltip_url = IFPWAP_PLUGIN_URL . 'assets/admin/images/tooltip_icon.png';
     10
    911?>
    1012<!-- Start form section -->
  • iflair-pwa-app/trunk/includes/admin/caching-strategies.php

    r3433574 r3438430  
    55$ifpwap_caching_type = get_option('ifpwap_caching_type');
    66$ifpwap_pre_caching_manual = get_option('ifpwap_pre_caching_manual');
    7 $ifpwap_tooltip_url = plugins_url().'/iflair-pwa-app/assets/admin/images/tooltip_icon.png';
     7// $ifpwap_tooltip_url = plugins_url().'/iflair-pwa-app/assets/admin/images/tooltip_icon.png';
     8$ifpwap_tooltip_url = IFPWAP_PLUGIN_URL.'assets/admin/images/tooltip_icon.png';
    89?>
    910<!-- Start form section -->
  • iflair-pwa-app/trunk/includes/admin/settings_fields.php

    r3433574 r3438430  
    1616$ifpwap_text_direction = get_option('ifpwap_text_direction');
    1717$ifpwap_custom_footer_btn = get_option('ifpwap_custom_footer_btn');
    18 $ifpwap_tooltip_url = plugins_url().'/iflair-pwa-app/assets/admin/images/tooltip_icon.png';
     18//$ifpwap_tooltip_url = plugins_url().'/iflair-pwa-app/assets/admin/images/tooltip_icon.png';
     19$ifpwap_tooltip_url = IFPWAP_PLUGIN_URL.'assets/admin/images/tooltip_icon.png';
    1920?>
    2021<!-- Start form section -->
  • iflair-pwa-app/trunk/readme.txt

    r3433574 r3438430  
    55Requires at least: 4.7
    66Tested up to: 6.9
    7 Stable tag: 1.1.4
     7Stable tag: 1.1.5
    88Requires PHP: 5.6
    99License: GPLv2 or later
     
    142142* Improved settings structure and labels
    143143* Minor code cleanup and compatibility fixes
     144
     145= 1.1.5 =
     146* Fixed hardcoded plugin paths and URLs for scripts, styles, and assets.
     147* Moved service worker, register JS, and manifest files to wp-content/uploads/iflair-pwa-app/.
     148* Updated all file URLs to use wp_upload_dir() dynamically.
     149* Added fallback to file_put_contents() if Filesystem API is not available.
     150* Status checker now correctly reads files from uploads folder.
     151* Plugin fully update-safe and multisite-compatible.
Note: See TracChangeset for help on using the changeset viewer.