Plugin Directory

Changeset 3222126


Ignore:
Timestamp:
01/14/2025 09:56:28 AM (15 months ago)
Author:
powr
Message:

Update plugin to version 2.0.0

Location:
powr-popup
Files:
14 added
1 edited

Legend:

Unmodified
Added
Removed
  • powr-popup/trunk/powr-popup.php

    r1825888 r3222126  
    11<?php
    2     /**
    3      * @package POWr Popup
    4      * @version 1.6.4
    5      */
    6     /*
    7     Plugin Name: POWr Popup
    8     Plugin URI: https://www.powr.io/plugins/popup
    9     Description: Capture contacts and promote offers with custom popups  Drop the widget anywhere in your theme. Or use the POWr icon in your WP text editor to add to a page or post. Edit on your live page by clicking the settings icon. More plugins and tutorials at POWr.io.
    10     Author: POWr.io
    11     Version: 1.6.4
    12     Author URI: https://www.powr.io
    13     */
    142
    15     ///////////////////////////////////////GENERATE JS IN HEADER///////////////////////////////
    16     //For local mode (testing)
    17     if(!function_exists('powr_local_mode')){
    18         function powr_local_mode(){
    19           return false;
    20         }
    21     }
    22     //Generates an instance key
    23     if(!function_exists('generate_powr_instance')){
    24         function generate_powr_instance() {
    25           $alphabet = 'abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789';
    26           $pass = array(); //remember to declare $pass as an array
    27           $alphaLength = strlen($alphabet) - 1; // Put the length -1 in cache.
    28           for ($i = 0; $i < 10; $i++) { // Add 10 random characters.
    29             $n = rand(0, $alphaLength);
    30             $pass[] = $alphabet[$n];
    31           }
    32           $pass_string = implode($pass) . time(); // Add the current time to avoid duplicate keys.
    33           return $pass_string; // Turn the array into a string.
    34         }
    35     }
    36     //Adds script to the header if necessary
    37     if(!function_exists('initialize_powr_js')){
    38         function initialize_powr_js(){
    39           //No matter what we want the javascript in the header:
    40           add_option( 'powr_token', generate_powr_instance(), '', 'yes' );  //Add a global powr token: (This will do nothing if the option already exists)
    41           $powr_token = get_option('powr_token'); //Get the global powr_token
    42           if(powr_local_mode()){//Determine JS url:
    43             $js_url = '//localhost:3000/powr_local.js?external-type=wordpress';
    44           }else{
    45             $js_url = '//www.powr.io/powr.js?external-type=wordpress';
    46           }
    47           ?>
    48           <script>
    49             (function(d){
    50               var js, id = 'powr-js', ref = d.getElementsByTagName('script')[0];
    51               if (d.getElementById(id)) {return;}
    52               js = d.createElement('script'); js.id = id; js.async = true;
    53               js.src = '<?php echo $js_url; ?>';
    54               js.setAttribute('powr-token','<?php echo $powr_token; ?>');
    55               ref.parentNode.insertBefore(js, ref);
    56             }(document));
    57           </script>
    58           <?php
    59         }
    60         //CALL INITIALIZE
    61         add_action( 'wp_enqueue_scripts', 'initialize_powr_js' );
    62     }
    63     //////////////////////////////////////////////////////////////////////////////////////////////////
    64     ///////////////////////////////////////Create Popup widget/////////////////////////////////
    65     class Powr_Popup extends WP_Widget{
    66       public $plugin;
    67       //Create the widget
    68       public function __construct(){
    69         parent::__construct( 'powr_popup',
    70                              __( 'POWr Popup' ),
    71                              array( 'description' => __( 'Popup by POWr.io') )
    72         );
    73        
    74       }
    75       //This prints the div
    76       public function widget( $args, $instance ){
    77         $label = $instance['label'];
    78        
    79         ?>
    80         <div class='widget powr-popup' label='<?php echo $label; ?>'></div>
    81         <?php
    82       }
    83       public function update( $new_instance, $old_instance ){
    84         $instance = $old_instance;
    85         //If no label, then set a label
    86         if( empty($instance['label']) ){
    87           $instance['label'] = 'wordpress_'.time();
    88         }
    89        
    90         return $instance;
    91       }
    92       public function form( $instance ){
    93        
    94         ?>
    95         <p>
    96           To edit, visit your live webpage and click the gears icon on your Popup.
    97         </p>
    98         <p>
    99           Learn more at <a href='https://www.powr.io/knowledge-base'>POWr.io</a>
    100         </p>
    101         <?php
    102       }
    103     }
    104     //Register Widget With WordPress
    105     function register_powr_popup() {
    106       register_widget( 'Powr_Popup' );
    107     }
    108     //Use widgets_init action hook to execute custom function
    109     add_action( 'widgets_init', 'register_powr_popup' );
    110     //Create short codes for adding plugins anywhere:
    111     function powr_popup_shortcode( $atts ){
    112       if(isset($atts['id'])){
    113         $id = $atts['id'];
    114         return "<div class='powr-popup' id='$id'></div>";
    115       }else if(isset($atts['label'])){
    116         $label = $atts['label'];
    117             return "<div class='powr-popup' label='$label'></div>";
    118       }else{
    119         "<div class='powr-popup'></div>";
    120       }
    121     }
    122     add_shortcode( 'powr-popup', 'powr_popup_shortcode' );
     3/**
     4 * The plugin bootstrap file
     5 *
     6 * This file is read by WordPress to generate the plugin information in the plugin
     7 * admin area. This file also includes all of the dependencies used by the plugin,
     8 * registers the activation and deactivation functions, and defines a function
     9 * that starts the plugin.
     10 *
     11 * @link              https://www.powr.io/popup-website-app
     12 * @since             2.0.0
     13 * @package           Powr_Popup
     14 *
     15 * @wordpress-plugin
     16 * Plugin Name:       POWr Popup
     17 * Plugin URI:        https://www.powr.io/popup-website-app
     18 * Description:       Increase conversions and get more sign-ups.
     19 * Version:           2.0.0
     20 * Author:            POWr
     21 * Author URI:        https://www.powr.io
     22 * License:           GPL-3.0-or-later
     23 * License URI:       http://www.gnu.org/licenses/gpl-3.0.html
     24 * Text Domain:       powr-popup
     25 */
    12326
    124     /* Add POWr Plug to tiny MCE */
    125     if( !function_exists('powr_tinymce_button') ){
    126       add_action( 'admin_init', 'powr_tinymce_button' ); //This calls the function below
     27// If this file is called directly, abort.
     28if (! defined('WPINC')) {
     29    die;
     30}
    12731
    128       function powr_tinymce_button() {
    129            if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pages' ) ) {
    130                 add_filter( 'mce_buttons', 'powr_register_tinymce_button' );
    131                 add_filter( 'mce_external_plugins', 'powr_add_tinymce_button' );
    132            }
    133       }
    134       function powr_register_tinymce_button( $buttons ) {
    135            array_push( $buttons, 'powr');
    136            return $buttons;
    137       }
    138       function powr_add_tinymce_button( $plugin_array ) {
    139            $plugin_array['powr'] = plugins_url( '/powr_tinymce.js', __FILE__ ) ;
    140            return $plugin_array;
    141       }
    142       //CSS For icon
    143       function powr_tinymce_css() {
    144           wp_enqueue_style('powr_tinymce', plugins_url('/powr_tinymce.css', __FILE__));
    145       }
    146       add_action('admin_enqueue_scripts', 'powr_tinymce_css');
    147     }
    148     //ADD MENUS
    149     add_action( 'admin_menu', 'powr_popup_menu' );
    150     function powr_popup_menu() {
    151       add_menu_page( 'POWr Popup', 'POWr Popup', 'manage_options', 'powr-popup-settings', 'powr_popup_options', plugins_url('/powr-icon.png',__FILE__));
    152     }
    153     function powr_popup_options() {
    154       if(powr_local_mode()){//Determine JS url:
    155         $redirect_url = 'https://localhost:3000/wp-create/popup';
    156       }else{
    157         $redirect_url = 'https://www.powr.io/wp-create/popup';
    158       }
    159       echo '<br><br><br><br><center><h2>Redirecting to POWr Dashboard...</h2></center>';
    160       echo '<script>';
    161       echo "window.location.assign('$redirect_url')";
    162       echo '</script>';
    163     }
    164     if( !function_exists('admin_handle_powr_ext_urls') ){
    165       add_action('in_admin_footer', 'admin_handle_powr_ext_urls');
    166       function admin_handle_powr_ext_urls(){
    167             echo '<script>';
    168         echo 'if( document.querySelector("a[class*=page_powr-]") ){ ';
    169           echo 'document.querySelector("a[class*=page_powr-]").target = "_blank"';
    170         echo '}';
    171             echo '</script>';
    172       }
    173       }
    174     //Redirecting to landing page when plugin is activated
    175     register_activation_hook(__FILE__, 'powr_popup_plugin_activate');
    176       add_action('admin_init', 'powr_popup_plugin_redirect');
     32define('PLUGIN_NAME_VERSION', '2.0.0');
    17733
    178       function powr_popup_plugin_activate() {
    179       add_option('powr_popup_plugin_do_activation_redirect', true);
    180       }
     34if (!function_exists('powrio_popup_menu')) {
     35    function powrio_popup_menu()
     36    {
     37        if (empty($GLOBALS['admin_page_hooks']['powrio-plugins']))
     38            add_menu_page(
     39                'Popup',
     40                'Popup',
     41                'manage_options',
     42                'powrio-popup',
     43                'powrio_powr_popup_options',
     44                plugins_url('/src/icons/powr-icon.png', __FILE__)
     45            );
     46    }
     47}
    18148
    182       $current_date = new DateTime();
    183       $current_timestamp = $current_date->format('U');
    184       add_option('powr_install_time', $current_timestamp, '', 'yes' );  //Add a global powr oauth token: (This will do nothing if the option already exists)
     49if (!function_exists('powrio_powr_base_url')) {
     50    function powrio_powr_base_url()
     51    {
     52        return 'www.powr-staging.io';
     53    }
     54}
    18555
    186       function powr_popup_plugin_redirect() {
    187       if (get_option('powr_popup_plugin_do_activation_redirect', false)) {
    188           delete_option('powr_popup_plugin_do_activation_redirect');
    189           if(!isset($_GET['activate-multi']))
    190           {
    191             wp_redirect( get_admin_url().'?platform=wordpress&page=powr-popup-settings&' );
    192           }
    193        }
    194       }
     56if (!function_exists('powrio_render_iframe')) {
     57    function powrio_render_iframe($url)
     58    {
     59        echo ('<iframe src="' . esc_url($url) . '" frameborder="0" scrolling="yes" seamless="seamless" style="background: white;display:block; width: calc(100% - -20px);; height: calc(100vh - 35px); margin-left: -20px;"></iframe>');
     60    }
     61}
    19562
     63if (!function_exists('powrio_powr_popup_options')) {
     64    function powrio_powr_popup_options()
     65    {
     66        $current_user = wp_get_current_user();
     67        powrio_render_iframe('https://' . powrio_powr_base_url() . '/api/woo_commerce/auth/apps/popup?email='.$current_user->user_email.'&platform=woocommerce&done=1');
     68    }
     69}
    19670
    197   ?>
     71add_action('admin_menu', 'powrio_popup_menu');
     72?>
Note: See TracChangeset for help on using the changeset viewer.