Plugin Directory

Changeset 2361962


Ignore:
Timestamp:
08/15/2020 03:53:28 PM (5 years ago)
Author:
coderevolution
Message:

fixed some critical issues

Location:
wp-pocket-urls
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • wp-pocket-urls/tags/1.0.0/assets/views/single-wp_pocketurl_link.php

    r2359978 r2361962  
    1919    $clicks->count_click($post->ID);
    2020}
    21 
    2221switch($redirect){
    2322    case '301':
  • wp-pocket-urls/tags/1.0.0/classes/class-wp-pocketurl-admin.php

    r2359978 r2361962  
    140140    public function register_wp_pocketurl_settings(){
    141141        add_settings_section( 'default_settings', '', array($this,'default_settings_callback'), 'wp_pocketurl_link_settings' );
    142         register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_enable_auto' );
    143         add_settings_field( 'wp_pocketurl_link_enable_auto', 'Enable Published Posts External Link Auto Shortening', array($this,'wp_pocketurl_auto_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
    144 
    145         register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_prefix' );
     142        register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_prefix' );
    146143        add_settings_field( 'wp_pocketurl_link_prefix', 'Link Prefix', array($this,'wp_pocketurl_link_prefix_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
    147144       
    148145        register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_redirection' );
    149         add_settings_field( 'wp_pocketurl_link_redirection', 'Link Redirection', array($this,'wp_pocketurl_link_redirection_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
     146        add_settings_field( 'wp_pocketurl_link_redirection', 'Default Link Redirection', array($this,'wp_pocketurl_link_redirection_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
    150147
    151148        register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_collect_data' );
     
    155152        add_settings_field( 'wp_pocketurl_link_exclude_cat', 'Do Not Add Category To Permalink', array($this,'wp_pocketurl_link_exclude_cat_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
    156153
    157         register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_exclude_word' );
    158         add_settings_field( 'wp_pocketurl_link_exclude_word', 'Banned URL String List', array($this,'wp_pocketurl_link_exclude_word_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
     154        register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_enable_auto' );
     155        add_settings_field( 'wp_pocketurl_link_enable_auto', 'Enable Published Posts External Link Auto Shortening', array($this,'wp_pocketurl_auto_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
     156
     157        register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_exclude_word' );
     158        add_settings_field( 'wp_pocketurl_link_exclude_word', 'Auto Shortening Banned URL String List', array($this,'wp_pocketurl_link_exclude_word_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
    159159       
    160160        register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_require_word' );
    161         add_settings_field( 'wp_pocketurl_link_require_word', 'Required URL String List', array($this,'wp_pocketurl_link_required_word_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
     161        add_settings_field( 'wp_pocketurl_link_require_word', 'Auto Shortening Required URL String List', array($this,'wp_pocketurl_link_required_word_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
    162162    }
    163163    // call back function for add settings section
  • wp-pocket-urls/tags/1.0.0/classes/class-wp-pocketurl.php

    r2359978 r2361962  
    1212}
    1313
     14register_activation_hook( __FILE__, 'wp_pocketurl_activate' );
     15/**
     16 * Add a flag that will allow to flush the rewrite rules when needed.
     17 */
     18function wp_pocketurl_activate() {
     19    if ( ! get_option( 'wp_pocketurl_flush_rewrite_rules_flag' ) ) {
     20        add_option( 'wp_pocketurl_flush_rewrite_rules_flag', true );
     21    }
     22}
     23
     24add_action( 'init', 'wp_pocketurl_flush_rewrite_rules_maybe', 20 );
     25/**
     26 * Flush rewrite rules if the previously added flag exists,
     27 * and then remove the flag.
     28 */
     29function wp_pocketurl_flush_rewrite_rules_maybe() {
     30    if ( get_option( 'wp_pocketurl_flush_rewrite_rules_flag' ) ) {
     31        flush_rewrite_rules();
     32        delete_option( 'wp_pocketurl_flush_rewrite_rules_flag' );
     33    }
     34}
     35
     36register_deactivation_hook( __FILE__, 'wp_pocketurl_flush_rewrite_rules' );
     37function wp_pocketurl_flush_rewrite_rules()
     38{
     39    flush_rewrite_rules();
     40}
     41
    1442class WP_PocketURLs{
    1543   
    1644    function __construct() {
    1745        //register custom post
    18         add_action( 'init', array($this,'wp_pocketurl_link_init'),0 );
     46        add_action( 'init', array($this, 'wp_pocketurl_link_init'),0 );
    1947        //register custom taxonomy
    20         add_action( 'init', array($this,'wp_pocketurl_link_category_init'), 0 );
     48        add_action( 'init', array($this, 'wp_pocketurl_link_category_init'), 0 );
    2149        //register link options box
    22         add_action( 'add_meta_boxes', array($this,'wp_pocketurl_link_options_init'), 0 );
     50        add_action( 'add_meta_boxes', array($this, 'wp_pocketurl_link_options_init'), 0 );
    2351        // register link clicks details box
    24         add_action( 'add_meta_boxes', array($this,'wp_pocketurl_link_clicks_details_init'), 0 );
     52        add_action( 'add_meta_boxes', array($this, 'wp_pocketurl_link_clicks_details_init'), 0 );
    2553        // save link options data
    26         add_action( 'save_post',array($this,'wp_pocketurl_link_options_save'));
     54        add_action( 'save_post',array($this, 'wp_pocketurl_link_options_save'));
    2755        // delete click data when post deleted
    28         add_action( 'before_delete_post', array($this,'wp_pocketurl_delete_click_data') );
     56        add_action( 'before_delete_post', array($this, 'wp_pocketurl_delete_click_data') );
    2957        //enqueue scripts and styles
    30         add_action('admin_enqueue_scripts',array($this,'enqueue_styles'));
    31         add_action('admin_enqueue_scripts',array($this,'enqueue_scripts'));
     58        add_action('admin_enqueue_scripts',array($this, 'enqueue_styles'));
     59        add_action('admin_enqueue_scripts',array($this, 'enqueue_scripts'));
    3260        //hook the single post template
    33         add_filter('single_template', array($this,'wp_pocketurl_link_template'));
    34 
     61        add_filter('single_template', array($this, 'wp_pocketurl_link_template'));
    3562    }
    3663
     
    130157        $args['rewrite'] = $rewrite;
    131158        register_post_type( 'wp_pocketurl_link', $args );
     159        flush_rewrite_rules();
    132160    }
    133161    // register taxonomy
     
    207235   
    208236    function wp_pocketurl_link_template($single){
    209          global $wp_query, $post;
     237         global $post;
     238         
    210239        /* Checks for single template by post type */
    211240        if ($post->post_type == "wp_pocketurl_link"){
    212241            if(file_exists(wp_pocketurl_path . 'assets/views/single-wp_pocketurl_link.php'))
     242            {
    213243                return wp_pocketurl_path . 'assets/views/single-wp_pocketurl_link.php';
     244            }
    214245        }
    215246        return $single;
  • wp-pocket-urls/trunk/assets/views/single-wp_pocketurl_link.php

    r2359978 r2361962  
    1919    $clicks->count_click($post->ID);
    2020}
    21 
    2221switch($redirect){
    2322    case '301':
  • wp-pocket-urls/trunk/classes/class-wp-pocketurl-admin.php

    r2359978 r2361962  
    140140    public function register_wp_pocketurl_settings(){
    141141        add_settings_section( 'default_settings', '', array($this,'default_settings_callback'), 'wp_pocketurl_link_settings' );
    142         register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_enable_auto' );
    143         add_settings_field( 'wp_pocketurl_link_enable_auto', 'Enable Published Posts External Link Auto Shortening', array($this,'wp_pocketurl_auto_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
    144 
    145         register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_prefix' );
     142        register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_prefix' );
    146143        add_settings_field( 'wp_pocketurl_link_prefix', 'Link Prefix', array($this,'wp_pocketurl_link_prefix_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
    147144       
    148145        register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_redirection' );
    149         add_settings_field( 'wp_pocketurl_link_redirection', 'Link Redirection', array($this,'wp_pocketurl_link_redirection_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
     146        add_settings_field( 'wp_pocketurl_link_redirection', 'Default Link Redirection', array($this,'wp_pocketurl_link_redirection_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
    150147
    151148        register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_collect_data' );
     
    155152        add_settings_field( 'wp_pocketurl_link_exclude_cat', 'Do Not Add Category To Permalink', array($this,'wp_pocketurl_link_exclude_cat_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
    156153
    157         register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_exclude_word' );
    158         add_settings_field( 'wp_pocketurl_link_exclude_word', 'Banned URL String List', array($this,'wp_pocketurl_link_exclude_word_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
     154        register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_enable_auto' );
     155        add_settings_field( 'wp_pocketurl_link_enable_auto', 'Enable Published Posts External Link Auto Shortening', array($this,'wp_pocketurl_auto_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
     156
     157        register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_exclude_word' );
     158        add_settings_field( 'wp_pocketurl_link_exclude_word', 'Auto Shortening Banned URL String List', array($this,'wp_pocketurl_link_exclude_word_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
    159159       
    160160        register_setting( 'wp_pocketurl_settings_group', 'wp_pocketurl_link_require_word' );
    161         add_settings_field( 'wp_pocketurl_link_require_word', 'Required URL String List', array($this,'wp_pocketurl_link_required_word_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
     161        add_settings_field( 'wp_pocketurl_link_require_word', 'Auto Shortening Required URL String List', array($this,'wp_pocketurl_link_required_word_callback'), 'wp_pocketurl_link_settings', 'default_settings' );
    162162    }
    163163    // call back function for add settings section
  • wp-pocket-urls/trunk/classes/class-wp-pocketurl.php

    r2359978 r2361962  
    1212}
    1313
     14register_activation_hook( __FILE__, 'wp_pocketurl_activate' );
     15/**
     16 * Add a flag that will allow to flush the rewrite rules when needed.
     17 */
     18function wp_pocketurl_activate() {
     19    if ( ! get_option( 'wp_pocketurl_flush_rewrite_rules_flag' ) ) {
     20        add_option( 'wp_pocketurl_flush_rewrite_rules_flag', true );
     21    }
     22}
     23
     24add_action( 'init', 'wp_pocketurl_flush_rewrite_rules_maybe', 20 );
     25/**
     26 * Flush rewrite rules if the previously added flag exists,
     27 * and then remove the flag.
     28 */
     29function wp_pocketurl_flush_rewrite_rules_maybe() {
     30    if ( get_option( 'wp_pocketurl_flush_rewrite_rules_flag' ) ) {
     31        flush_rewrite_rules();
     32        delete_option( 'wp_pocketurl_flush_rewrite_rules_flag' );
     33    }
     34}
     35
     36register_deactivation_hook( __FILE__, 'wp_pocketurl_flush_rewrite_rules' );
     37function wp_pocketurl_flush_rewrite_rules()
     38{
     39    flush_rewrite_rules();
     40}
     41
    1442class WP_PocketURLs{
    1543   
    1644    function __construct() {
    1745        //register custom post
    18         add_action( 'init', array($this,'wp_pocketurl_link_init'),0 );
     46        add_action( 'init', array($this, 'wp_pocketurl_link_init'),0 );
    1947        //register custom taxonomy
    20         add_action( 'init', array($this,'wp_pocketurl_link_category_init'), 0 );
     48        add_action( 'init', array($this, 'wp_pocketurl_link_category_init'), 0 );
    2149        //register link options box
    22         add_action( 'add_meta_boxes', array($this,'wp_pocketurl_link_options_init'), 0 );
     50        add_action( 'add_meta_boxes', array($this, 'wp_pocketurl_link_options_init'), 0 );
    2351        // register link clicks details box
    24         add_action( 'add_meta_boxes', array($this,'wp_pocketurl_link_clicks_details_init'), 0 );
     52        add_action( 'add_meta_boxes', array($this, 'wp_pocketurl_link_clicks_details_init'), 0 );
    2553        // save link options data
    26         add_action( 'save_post',array($this,'wp_pocketurl_link_options_save'));
     54        add_action( 'save_post',array($this, 'wp_pocketurl_link_options_save'));
    2755        // delete click data when post deleted
    28         add_action( 'before_delete_post', array($this,'wp_pocketurl_delete_click_data') );
     56        add_action( 'before_delete_post', array($this, 'wp_pocketurl_delete_click_data') );
    2957        //enqueue scripts and styles
    30         add_action('admin_enqueue_scripts',array($this,'enqueue_styles'));
    31         add_action('admin_enqueue_scripts',array($this,'enqueue_scripts'));
     58        add_action('admin_enqueue_scripts',array($this, 'enqueue_styles'));
     59        add_action('admin_enqueue_scripts',array($this, 'enqueue_scripts'));
    3260        //hook the single post template
    33         add_filter('single_template', array($this,'wp_pocketurl_link_template'));
    34 
     61        add_filter('single_template', array($this, 'wp_pocketurl_link_template'));
    3562    }
    3663
     
    130157        $args['rewrite'] = $rewrite;
    131158        register_post_type( 'wp_pocketurl_link', $args );
     159        flush_rewrite_rules();
    132160    }
    133161    // register taxonomy
     
    207235   
    208236    function wp_pocketurl_link_template($single){
    209          global $wp_query, $post;
     237         global $post;
     238         
    210239        /* Checks for single template by post type */
    211240        if ($post->post_type == "wp_pocketurl_link"){
    212241            if(file_exists(wp_pocketurl_path . 'assets/views/single-wp_pocketurl_link.php'))
     242            {
    213243                return wp_pocketurl_path . 'assets/views/single-wp_pocketurl_link.php';
     244            }
    214245        }
    215246        return $single;
Note: See TracChangeset for help on using the changeset viewer.