Plugin Directory

Changeset 1874793


Ignore:
Timestamp:
05/15/2018 04:04:41 PM (8 years ago)
Author:
snappic
Message:

Fixes .htaccess / rewrite issues.

Location:
snappic/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • snappic/trunk/assets/css/snappic-welcome.css

    r1715114 r1874793  
    237237  top: 4px;
    238238}
     239.permalink_error {
     240    margin-top: 2em;
     241}
    239242.subtitle{
    240243  text-transform: uppercase;
  • snappic/trunk/assets/js/snappic-welcome.js

    r1715114 r1874793  
    1212        $.ajax
    1313            ({
    14                 url: snappic_for_woocommerce.permalink_url,
     14                url: snappic_for_woocommerce.ajaxurl,
    1515                type: 'post',
    16                 beforeSend: function ( xhr ) {
    17                     xhr.setRequestHeader( 'X-WP-Nonce', snappic_for_woocommerce.nonce );
    18                 },
    19                 success: function(result)
     16                data: {
     17                    'action': 'snappic_update_permalinks',
     18                    'nonce': snappic_for_woocommerce.nonce
     19                },
     20                success: function(response)
    2021                {
    2122                    $_this.removeClass('loading').prop('disabled', true);
    22                     $slides.addClass( 'pick_plan' );
     23                    if( response == 1 ) {
     24                        $slides.addClass( 'pick_plan' );
     25                    } else {
     26                        $('#change_url_structure .permalink_error').slideDown();
     27                    }
    2328                }
    2429            });
  • snappic/trunk/includes/admin/views/html-snappic-welcome.php

    r1715114 r1874793  
    3535        <div class="subtitle"><?php _e( 'THIS ALLOWS US TO SYNC UP WITH YOUR INVENTORY AND STOP SHOWING ADS FOR PRODUCTS ONCE THEY ARE OUT OF STOCK', 'snappic-for-woocommerce' );?></div>
    3636        <a href='#pick_plan' class="button-blue js-goto update-permalink" data-goto="pick_plan"><?php _e( 'Change and Continue', 'snappic-for-woocommerce' );?></a>
     37        <div class="permalink_error" style="display:none;"><p><?php _e( 'Sorry, we were not able to update your permalinks at this time.', 'snappic-for-woocommerce' );?></p></div>
    3738        <div class="note"><?php _e( 'This won’t change how your website looks or any of your products', 'snappic-for-woocommerce' );?></div>
    3839      </div>
  • snappic/trunk/includes/class-snappic-admin-setup-wizard.php

    r1715114 r1874793  
    4848
    4949        $l10n = array(
    50             'nonce' => wp_create_nonce( 'wp_rest' ),
    51             'permalink_url' => esc_url_raw( rest_url( 'wc/v1/snappic/store/update' ) ),
     50            'nonce' => wp_create_nonce( 'snappic_update' ),
     51            'ajaxurl' => admin_url( 'admin-ajax.php' ),
    5252             );
    5353        wp_localize_script( 'snappic-welcome', 'snappic_for_woocommerce ', $l10n );
  • snappic/trunk/includes/class-snappic-api-controller.php

    r1715114 r1874793  
    3232      ),
    3333      'schema' => array( $this, 'get_public_item_schema' ),
    34     ) );
    35 
    36     register_rest_route( $this->namespace, '/' . $this->rest_base . '/update', array(
    37       array(
    38         'methods'             => WP_REST_Server::EDITABLE,
    39         'callback'            => array( $this, 'update_permalinks' ),
    40         'permission_callback' => array( $this, 'update_permalinks_permissions_check' ),
    41       )
    42     ) );
    43 
    44     register_rest_route( $this->namespace, '/' . $this->rest_base . '/signup', array(
    45       array(
    46         'methods'             => WP_REST_Server::EDITABLE,
    47         'callback'            => array( $this, 'get_signup_link' ),
    48         'permission_callback' => array( $this, 'update_permalinks_permissions_check' ),
    49       )
    5034    ) );
    5135
     
    10286   * Makes sure the current user has access to WRITE the settings APIs.
    10387   *
    104    * @since  3.0.0
     88   * @since  1.0.0
     89   * @deprecated 1.1.0
     90   *
    10591   * @param WP_REST_Request $request Full data about the request.
    10692   * @return WP_Error|boolean
    10793   */
    108   public function update_permalinks_permissions_check( $request ) {
     94  public function update_permalinks_permissions_check( $request ) {
     95    _deprecated_function( 'WC_Free_Gift_Coupons::update_permalinks', '1.1.0', 'Snappic_Base::update_permalinks()' );
    10996    if ( ! wc_rest_check_manager_permissions( 'settings', 'edit' ) ) {
    11097      return new WP_Error( 'woocommerce_rest_cannot_edit', __( 'Sorry, you cannot edit the permalinks.', 'snappic-for-woocommerce' ), array( 'status' => rest_authorization_required_code() ) );
     
    116103  /**
    117104   * Check whether a given request has permission to read data.
     105   *
     106   * @since 1.0.0
     107   * @deprecated 1.1.0 - process now occurs via AJAX callback, see Snappic_Base::update_permalinks()
    118108   *
    119109   * @param  WP_REST_Request $request Full details about the request.
     
    121111   */
    122112  public function update_permalinks( $request ) {
    123     $data = array( 'status' => update_option( 'permalink_structure', "/%postname%/" ) );
     113    _deprecated_function( 'WC_Free_Gift_Coupons::update_permalinks', '1.1.0', 'Snappic_Base::update_permalinks()' );
     114    $data = array( 'status' => update_option( 'permalink_structure', "/%year%/%monthnum%/%postname%/" ) );
    124115    flush_rewrite_rules();
    125116    return rest_ensure_response( $data );
  • snappic/trunk/languages/snappic-for-woocommerce.pot

    r1821537 r1874793  
    33msgid ""
    44msgstr ""
    5 "Project-Id-Version: Snappic for WooCommerce 1.0.6\n"
     5"Project-Id-Version: Snappic for WooCommerce 1.0.7\n"
    66"Report-Msgid-Bugs-To: "
    77"https://wordpress.org/support/plugin/snappic-for-woocommerce\n"
  • snappic/trunk/package.json

    r1821537 r1874793  
    22  "title": "Snapppic for WooCommerce",
    33  "name": "snappic-for-woocommerce",
    4   "version": "1.0.6",
     4  "version": "1.0.7",
    55  "description": "Snappic Integration",
    66  "main": "Gruntfile.js",
  • snappic/trunk/readme.txt

    r1821537 r1874793  
    55Requires at least: 4.7
    66Tested up to: 4.8
    7 Stable tag: 1.0.6
     7Stable tag: 1.0.7
    88License: GPLv3
    99License URI: http://www.gnu.org/licenses/gpl-3.0.html
  • snappic/trunk/snappic-for-woocommerce.php

    r1821537 r1874793  
    1515
    1616class Snappic_Base {
    17     const VERSION = '1.0.6';
     17    const VERSION = '1.0.7';
    1818    const REQUIRED_WOO = '3.1.0';
    1919
     
    6767        add_filter( 'rest_api_init', array( $this, 'add_api_resource' ) );
    6868
     69        // Ajax callback for updating permalinks
     70        add_action( 'wp_ajax_snappic_update_permalinks', array( $this, 'update_permalinks' ) );
     71
    6972        /*
    7073         * Save routine workaround
     
    284287
    285288        unload_textdomain( 'snappic' );
    286         load_plugin_textdomain( 'snappic', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
     289        load_plugin_textdomain( 'snappic-for-woocommerce', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
    287290    }
    288291
     
    339342    }
    340343
     344
     345    /**
     346     * Update the Permalinks via AJAX
     347     * Using an AJAX callback is preferred to using a REST route because it ensures that the functions that write the HTACCESS are available.
     348     *
     349     * @return string json-encoded
     350     */
     351    public function update_permalinks() {
     352
     353        global $wp_rewrite;
     354
     355        $permalink_structure = "/%postname%/";
     356
     357        if ( ! isset( $_POST[ 'nonce' ] ) || ! wp_verify_nonce( $_POST[ 'nonce' ], 'snappic_update' ) ) {
     358            wp_die();
     359        }
     360
     361        if ( ! current_user_can( 'manage_options' ) ) {
     362            wp_die();
     363        }
     364
     365        $wp_rewrite->set_permalink_structure( $permalink_structure );
     366        flush_rewrite_rules();
     367        wp_die('1');
     368
     369    }
     370
     371
    341372    /*-----------------------------------------------------------------------------------*/
    342373    /*  Helpers                                                                   */
Note: See TracChangeset for help on using the changeset viewer.