Plugin Directory

Changeset 2841301


Ignore:
Timestamp:
12/29/2022 10:01:25 PM (3 years ago)
Author:
alvinmuthui
Message:

version 2.0.0

Location:
tori-ajax
Files:
440 added
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • tori-ajax/trunk/README.txt

    r2754211 r2841301  
    44Tags: tori_ajax, ajax, wordpress, toria_add_ajax, javascript
    55Requires at least: 3.0.0
    6 Tested up to:  6.0
    7 Stable tag: 1.2.0
     6Tested up to:  6.1.1
     7Stable tag: 2.0.0
    88Requires PHP: 5.6.20
    99License: GPLv2 or later
     
    189189`apply_filters( 'toria/ajax/ajax_variables', $ajax_variables, $action, $php_callback, $script_path, $mode, $nonce, $ajax_object, $ajax_handle, $script_depends, $script_version, $script_in_footer );`
    190190
     191= 2.0.0 =
     192* Compatible with WordPress 6.1.1.
     193* Fix: Ajax in **private** mode is only accessible by signed-in users and those in **public** are only accessible by signed-out users.
     194* Pro version available.
     195
    191196== Upgrade Notice ==
    192197
    193 = 1.2.0 =
    194 * Added more parameters to some filters.
     198= 2.0.0 =
     199* Pro version available.
    195200
    196201== About ==
  • tori-ajax/trunk/includes/ajax/class-toria-ajax.php

    r2754211 r2841301  
    2121
    2222    /**
     23     * Holds Toria instance
     24     *
     25     * @since    2.0.0
     26     *
     27     * @var Toria
     28     */
     29    protected Toria $toria;
     30
     31    /**
    2332     * Unique action name
    2433     *
     
    125134     * Define the core functionality of the plugin.
    126135     *
     136     * @since    1.0.0
     137     * @since 1.0.2 Added $script_depends,$script_version, and $script_in_footer arguments.
     138     * @since 1.1.0 Added filters in the function definition.
     139     * @since 2.0.0 Added param $toria.
     140     *
     141     * @access   public
     142     *
     143     * @param Toria  $toria holds instance of Toria class.
    127144     * @param string $action The name of action.
    128145     * @param mixed  $php_callback PHP function to respond to ajax calls.
     
    136153     * @param mixed  $script_version String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If the version is set to false, a version number is automatically added equal to the current installed Tori Ajax version. If set to null, no version is added.
    137154     * @param bool   $script_in_footer Whether to enqueue the script before </body> instead of in the <head>.
    138      *
    139      * @since    1.0.0
    140      * @since 1.0.2 Added $script_depends,$script_version, and $script_in_footer arguments.
    141      * @since 1.1.0 Added filters in the function definition.
    142      * @access   public
    143155     */
    144156    public function __construct(
     157        Toria $toria,
    145158        $action,
    146159        $php_callback,
     
    156169    ) {
    157170        // Process variables before use.
     171        $this->toria = $toria;
    158172        if ( '' === $ajax_handle ) {
    159173            $ajax_handle = $action;
     
    162176        }
    163177        if ( false === $script_version ) {
    164             global $toria;
    165             $script_version = $toria->get_version();
     178            $script_version = $this->toria->get_version();
    166179        }
    167180
     
    201214     */
    202215    public function create_ajax() {
    203         if ( 'both' === $this->mode ) {
    204             $this->add_private_ajax();
    205             $this->add_public_ajax();
    206         } elseif ( 'private' === $this->mode ) {
    207             $this->add_private_ajax();
    208         } elseif ( 'public' === $this->mode ) {
    209             $this->add_public_ajax();
    210         }
    211 
     216        if ( is_user_logged_in() ) {
     217            if ( ( 'both' === $this->mode || 'private' === $this->mode ) ) {
     218                $this->add_private_ajax();
     219                $this->admin_enqueue_scripts();
     220                $this->frontend_enqueue_scripts();
     221            }
     222        } else {
     223            // signed out user on front end.
     224            if ( ( 'both' === $this->mode || 'public' === $this->mode ) ) {
     225                $this->add_public_ajax();
     226                $this->frontend_enqueue_scripts();
     227            }
     228        }
     229    }
     230
     231    /**
     232     * Add admin script
     233     *
     234     * @since    2.0.0
     235     * @access   public
     236     */
     237    public function admin_enqueue_scripts() {
     238        add_action( 'admin_enqueue_scripts', array( $this, 'toria_enqueue_script_callback' ) );
     239    }
     240
     241    /**
     242     * Add frond end script
     243     *
     244     * @since    2.0.0
     245     * @access   public
     246     */
     247    public function frontend_enqueue_scripts() {
     248        add_action( 'wp_enqueue_scripts', array( $this, 'toria_enqueue_script_callback' ) );
    212249    }
    213250
     
    220257    public function add_public_ajax() {
    221258        add_action( 'wp_ajax_nopriv_' . $this->action, array( $this, 'toria_ajax_callback' ) );
    222         add_action( 'wp_enqueue_scripts', array( $this, 'toria_enqueue_script_callback' ) );
    223259    }
    224260
     
    230266     */
    231267    public function add_private_ajax() {
    232         add_action( 'wp_ajax_' . $this->action, array( $this, 'toria_ajax_callback' ) );
    233         add_action( 'admin_enqueue_scripts', array( $this, 'toria_enqueue_script_callback' ) );
     268            add_action( 'wp_ajax_' . $this->action, array( $this, 'toria_ajax_callback' ) );
    234269    }
    235270
     
    246281        }
    247282
    248         global $toria;
    249         $allowed_html = $toria->get_allowed_html();
    250         if ( $toria->get_wp_version_value() >= 3.6 ) {
     283        $allowed_html = $this->toria->get_allowed_html();
     284        if ( $this->toria->get_wp_version_value() >= 3.6 ) {
    251285            if ( ! wp_verify_nonce( wp_kses( wp_unslash( $_REQUEST['nonce'] ), $allowed_html ), $this->nonce ) ) {
    252286                $msg = __( 'Nonce verification failed', 'toria' );
     
    287321     */
    288322    private function terminate( $message = '' ) {
    289         global $toria;
    290         $wp_version_value = $toria->get_wp_version_value();
     323        $wp_version_value = $this->toria->get_wp_version_value();
    291324        if ( '' !== $message ) {
    292325            if ( $wp_version_value >= 4.1 ) {
     
    300333        if ( $wp_version_value >= 3.4 ) {
    301334            if ( '' !== $message ) {
    302                 wp_die( wp_kses( $message, $toria->get_allowed_html() ) );
     335                wp_die( wp_kses( $message, $this->toria->get_allowed_html() ) );
    303336            }
    304337            wp_die();
    305338        } else {
    306339            if ( '' !== $message ) {
    307                 die( wp_kses( $message, $toria->get_allowed_html() ) );
     340                die( wp_kses( $message, $this->toria->get_allowed_html() ) );
    308341            }
    309342            die;
  • tori-ajax/trunk/includes/class-toria-ajax-api.php

    r2754211 r2841301  
    2828    public $ajax_objects;
    2929
     30    /**
     31     * Holds Toria instance
     32     *
     33     * @since    2.0.0
     34     *
     35     * @var Toria
     36     */
     37    protected Toria $toria;
    3038
    3139    /**
     
    3341     *
    3442     * @since    1.0.0
     43     * @since    2.0.0 added parameter toria
     44     *
     45     * @param Toria $toria Toria Instance.
    3546     */
    36     public function __construct() {
     47    public function __construct( Toria $toria ) {
     48        $this->toria        = $toria;
    3749        $this->ajax_objects = array();
    3850    }
     
    7688        if ( ! array_key_exists( $action, $this->ajax_objects ) ) {
    7789            $this->ajax_objects[ $action ] = new Toria_Ajax(
     90                $this->toria,
    7891                $action,
    7992                $php_callback,
     
    94107
    95108    }
    96     // Todo: Add function to return all ajax objects in array.
     109
     110    /**
     111     * Gets $jax_objects
     112     *
     113     * @since 2.0.0
     114     *
     115     * @return array
     116     */
     117    public function get_ajax_objects() {
     118        return $this->ajax_objects;
     119    }
    97120}
  • tori-ajax/trunk/includes/class-toria.php

    r2754211 r2841301  
    8585
    8686    /**
     87     * Plugin base_url.
     88     *
     89     * @since 2.0.0
     90     *
     91     * @var [type]
     92     */
     93    protected $plugin_base_url;
     94
     95    /**
    8796     * Define the core functionality of the plugin.
    8897     *
     
    97106            $this->version = TORIA_VERSION;
    98107        } else {
    99             $this->version = '1.2.0';
     108            $this->version = '2.0.0';
    100109        }
    101110        $this->plugin_name  = 'toria';
    102111        $this->allowed_html = array();
     112        $this->plugin_base_url  = plugin_dir_url( __DIR__ );
     113        $this->capability   = 'update_core';// 'administrator'
    103114        $this->set_wp_version_value();
    104115
     
    106117        $this->set_locale();
    107118        $this->init_ajax_api();
     119        $this->define_admin_hooks();
    108120
    109121    }
     
    148160         */
    149161        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/ajax/class-toria-ajax.php';
     162
     163        /**
     164         * The class responsible for defining all actions that occur in the admin area.
     165         */
     166        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-toria-admin.php';
    150167
    151168        $this->loader = new Toria_Loader();
     
    197214     */
    198215    private function init_ajax_api() {
    199 
    200         $this->ajax_api = new Toria_Ajax_API();
     216        $this->ajax_api = new Toria_Ajax_API( $this );
    201217    }
    202218
     
    246262            $script_in_footer
    247263        );
    248 
     264    }
     265
     266    /**
     267     * Register all of the hooks related to the admin area functionality
     268     * of the plugin.
     269     *
     270     * @since    2.0.0
     271     * @access   private
     272     */
     273    private function define_admin_hooks() {
     274
     275        $plugin_admin = new Toria_Admin( $this );
     276        // instantiate meta boxes on the post edit screen.
     277        if ( is_admin() ) {
     278            $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' );
     279            $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' );
     280            $this->loader->add_action( 'init', $plugin_admin, 'admin_menu' );
     281        }
    249282    }
    250283
     
    309342    }
    310343
     344    /**
     345     * Returns $this->capability
     346     *
     347     * @since 2.0.0
     348     *
     349     * @return mixed
     350     */
     351    public function get_capability() {
     352        return apply_filters( 'toria/setting/capability', $this->capability, $this );// phpcs:ignore;
     353    }
     354
     355    /**
     356     * Gets plugin_base_url
     357     *
     358     * @since 2.0.0
     359     *
     360     * @return string
     361     */
     362    public function get_plugin_base_url() {
     363        return $this->plugin_base_url;
     364    }
    311365
    312366}
  • tori-ajax/trunk/toria.php

    r2754211 r2841301  
    1616 * Plugin URI:        http://toriajax.com/
    1717 * Description:       Adds Ajax in WordPress with a few lines of code.
    18  * Version:           1.2.0
     18 * Version:           2.0.0
    1919 * Author:            Alvin Muthui
    2020 * Author URI:        https://profiles.wordpress.org/alvinmuthui/
     
    3030}
    3131
    32 /**
    33  * Currently plugin version.
    34  */
    35 define( 'TORIA_VERSION', '1.2.0' );
    36 
    37 /**
    38  * The code that runs during plugin activation.
    39  * This action is documented in includes/class-toria-activator.php
    40  */
    41 function activate_toria() {
    42     require_once plugin_dir_path( __FILE__ ) . 'includes/class-toria-activator.php';
    43     Toria_Activator::activate();
    44 }
    45 
    46 /**
    47  * The code that runs during plugin deactivation.
    48  * This action is documented in includes/class-toria-deactivator.php
    49  */
    50 function deactivate_toria() {
    51     require_once plugin_dir_path( __FILE__ ) . 'includes/class-toria-deactivator.php';
    52     Toria_Deactivator::deactivate();
    53 }
    54 
    55 register_activation_hook( __FILE__, 'activate_toria' );
    56 register_deactivation_hook( __FILE__, 'deactivate_toria' );
    57 
    58 /**
    59  * The core plugin class that is used to define internationalization,
    60  * admin-specific hooks, and public-facing site hooks.
    61  */
    62 require plugin_dir_path( __FILE__ ) . 'includes/class-toria.php';
    63 
    64 /**
    65  * Begins execution of the plugin.
    66  *
    67  * Since everything within the plugin is registered via hooks,
    68  * then kicking off the plugin from this point in the file does
    69  * not affect the page life cycle.
    70  *
    71  * @since    1.0.0
    72  */
    73 function init_toria() {
    74 
    75     $toria = new Toria();
    76     $toria->run();
    77     return $toria;
    78 
    79 }
    80 $toria = init_toria();
    81 
    82 /**
    83  * Adds Ajax scripts and their associated actions and callback
    84  *
    85  * @param string $action The name of the Ajax action.
    86  * @param mixed  $php_callback PHP function to respond to ajax calls.
    87  * @param string $script_path File path containing you Javascript file.
    88  * @param string $mode (string) Determines if script will be exposed to authenticated Ajax actions for logged-in users or non-authenticated Ajax actions for logged-out users or both. Using both, private, and public.
    89  * @param array  $ajax_variables Variables to be passed to be available for JS to utilize.
    90  * @param string $nonce (string) Used to create WP nonce for verification on PHP callback.
    91  * @param string $ajax_object (string) Name of object to be storing JS variables.
    92  * @param string $ajax_handle Name of script.
    93  * @param array  $script_depends (string[]) (Optional) An array of registered script handles this script depends on. Default value: array().
    94  * @param mixed  $script_version String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If the version is set to false, a version number is automatically added equal to the current installed Tori Ajax version. If set to null, no version is added. Default value: false.
    95  * @param bool   $script_in_footer (bool) (Optional) Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
    96  * @return bool Whether it is added or not.
    97  *
    98  * @since    1.0.0
    99  * @since    1.0.2 Added $script_depends, $script_version, and $script_in_footer arguments.
    100  * @access   public
    101  */
    102 function toria_add_ajax(
    103     $action,
    104     $php_callback,
    105     $script_path,
    106     $mode = 'private',
    107     $ajax_variables = array(),
    108     $nonce = 'my_custom_value_submission_test',
    109     $ajax_object = 'toria',
    110     $ajax_handle = '',
    111     $script_depends = array(),
    112     $script_version = false,
    113     $script_in_footer = true
    114 ) {
    115     global $toria;
    116     return $toria->add_ajax(
     32
     33if ( function_exists( 'toria_fs' ) ) {
     34    toria_fs()->set_basename( false, __FILE__ );
     35} else {
     36    if ( ! function_exists( 'toria_fs' ) ) {
     37
     38        /**
     39         * FS
     40         *
     41         * @since 2.0.0
     42         *
     43         * @return mixed
     44         */
     45        function toria_fs() {
     46            global $toria_fs;
     47
     48            if ( ! isset( $toria_fs ) ) {
     49                // Activate multisite network integration.
     50                if ( ! defined( 'WP_FS__PRODUCT_11581_MULTISITE' ) ) {
     51                    define( 'WP_FS__PRODUCT_11581_MULTISITE', true );
     52                }
     53
     54                // Include Freemius SDK.
     55                require_once dirname( __FILE__ ) . '/freemius/start.php';
     56
     57                $toria_fs = fs_dynamic_init(
     58                    array(
     59                        'id'                  => '11581',
     60                        'slug'                => 'toria',
     61                        'premium_slug'        => 'toria_pro',
     62                        'type'                => 'plugin',
     63                        'public_key'          => 'pk_bd8b9c9b8493ec8bcca873c28ff10',
     64                        'is_premium'          => true,
     65                        'premium_suffix'      => 'Pro',
     66                        'has_premium_version' => false,
     67                        'has_addons'          => false,
     68                        'has_paid_plans'      => true,
     69                        'trial'               => array(
     70                            'days'               => 7,
     71                            'is_require_payment' => true,
     72                        ),
     73                        'menu'                => array(
     74                            'slug'       => 'toria',
     75                            'first-path' => 'admin.php?page=toria',
     76                        ),
     77                    )
     78                );
     79            }
     80
     81            return $toria_fs;
     82        }
     83
     84        // Init Freemius.
     85        toria_fs();
     86        // Signal that SDK was initiated.
     87        do_action( 'toria_fs_loaded' );
     88    }
     89
     90    /**
     91     * Currently plugin version.
     92     */
     93    define( 'TORIA_VERSION', '2.0.0' );
     94
     95    /**
     96     * The code that runs during plugin activation.
     97     * This action is documented in includes/class-toria-activator.php
     98     */
     99    function activate_toria() {
     100        require_once plugin_dir_path( __FILE__ ) . 'includes/class-toria-activator.php';
     101        Toria_Activator::activate();
     102    }
     103
     104    /**
     105     * The code that runs during plugin deactivation.
     106     * This action is documented in includes/class-toria-deactivator.php
     107     */
     108    function deactivate_toria() {
     109        require_once plugin_dir_path( __FILE__ ) . 'includes/class-toria-deactivator.php';
     110        Toria_Deactivator::deactivate();
     111    }
     112
     113    /**
     114     * The code that runs during plugin uninstall.
     115     * This action is documented in includes/class-toria-uninstaller.php
     116     *
     117     * @since 2.0.0
     118     *
     119     * @return void
     120     */
     121    function toria_fs_uninstall_cleanup() {
     122        require_once plugin_dir_path( __FILE__ ) . 'includes/class-toria-uninstaller.php';
     123        Toria_Uninstaller::uninstall();
     124    }
     125
     126    register_activation_hook( __FILE__, 'activate_toria' );
     127    register_deactivation_hook( __FILE__, 'deactivate_toria' );
     128    toria_fs()->add_action( 'after_uninstall', 'toria_fs_uninstall_cleanup' );
     129
     130    /**
     131     * The core plugin class that is used to define internationalization,
     132     * admin-specific hooks, and public-facing site hooks.
     133     */
     134    require plugin_dir_path( __FILE__ ) . 'includes/class-toria.php';
     135
     136    /**
     137     * Begins execution of the plugin.
     138     *
     139     * Since everything within the plugin is registered via hooks,
     140     * then kicking off the plugin from this point in the file does
     141     * not affect the page life cycle.
     142     *
     143     * @since    1.0.0
     144     */
     145    function init_toria() {
     146
     147        $toria = new Toria();
     148        $toria->run();
     149        return $toria;
     150
     151    }
     152    $toria = init_toria();
     153
     154    /**
     155     * Adds Ajax scripts and their associated actions and callback
     156     *
     157     * @param string $action The name of the Ajax action.
     158     * @param mixed  $php_callback PHP function to respond to ajax calls.
     159     * @param string $script_path File path containing you Javascript file.
     160     * @param string $mode (string) Determines if script will be exposed to authenticated Ajax actions for logged-in users or non-authenticated Ajax actions for logged-out users or both. Using both, private, and public.
     161     * @param array  $ajax_variables Variables to be passed to be available for JS to utilize.
     162     * @param string $nonce (string) Used to create WP nonce for verification on PHP callback.
     163     * @param string $ajax_object (string) Name of object to be storing JS variables.
     164     * @param string $ajax_handle Name of script.
     165     * @param array  $script_depends (string[]) (Optional) An array of registered script handles this script depends on. Default value: array().
     166     * @param mixed  $script_version String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If the version is set to false, a version number is automatically added equal to the current installed Tori Ajax version. If set to null, no version is added. Default value: false.
     167     * @param bool   $script_in_footer (bool) (Optional) Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
     168     * @return bool Whether it is added or not.
     169     *
     170     * @since    1.0.0
     171     * @since    1.0.2 Added $script_depends, $script_version, and $script_in_footer arguments.
     172     * @access   public
     173     */
     174    function toria_add_ajax(
    117175        $action,
    118176        $php_callback,
    119177        $script_path,
    120         $mode,
    121         $ajax_variables,
    122         $nonce,
    123         $ajax_object,
    124         $ajax_handle,
    125         $script_depends,
    126         $script_version,
    127         $script_in_footer
    128     );
     178        $mode = 'private',
     179        $ajax_variables = array(),
     180        $nonce = 'my_custom_value_submission_test',
     181        $ajax_object = 'toria',
     182        $ajax_handle = '',
     183        $script_depends = array(),
     184        $script_version = false,
     185        $script_in_footer = true
     186    ) {
     187        global $toria;
     188        return $toria->add_ajax(
     189            $action,
     190            $php_callback,
     191            $script_path,
     192            $mode,
     193            $ajax_variables,
     194            $nonce,
     195            $ajax_object,
     196            $ajax_handle,
     197            $script_depends,
     198            $script_version,
     199            $script_in_footer
     200        );
     201    }
    129202}
    130203
    131204
     205
     206
     207
     208
     209
     210
     211
Note: See TracChangeset for help on using the changeset viewer.