Plugin Directory

Changeset 2174745


Ignore:
Timestamp:
10/17/2019 08:28:08 AM (6 years ago)
Author:
afoucret
Message:

bump version to v2.0.2

Location:
swiftype-search/trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • swiftype-search/trunk/AbstractSwiftypeComponent.php

    r2056911 r2174745  
    7171        return $this->client;
    7272    }
     73
     74    /**
     75     * Check if currently executing WP_CLI.
     76     *
     77     * @return boolean
     78     */
     79    public function isWpCLI()
     80    {
     81        return (defined('WP_CLI') && WP_CLI == true) || php_sapi_name () == 'cli';
     82    }
    7383}
  • swiftype-search/trunk/Admin/Action.php

    r2056911 r2174745  
    2424        parent::__construct();
    2525
     26        if ($this->isWpCLI()) {
     27            $this->installHooks();
     28        }
     29
     30        \add_action('admin_init', function() {
     31          if (\current_user_can('manage_options')) {
     32              $this->installHooks();
     33          }
     34        });
     35    }
     36
     37    /**
     38     * Install hooks for the admin actions.
     39     */
     40    public function installHooks() {
    2641        \add_action('wp_ajax_index_batch_of_posts', [$this, 'asyncIndexBatchOfPosts']);
    2742        \add_action('wp_ajax_delete_batch_of_trashed_posts', [$this, 'asyncDeleteBatchOfTrashedPosts']);
     
    107122    public function setApiKey()
    108123    {
     124        \check_ajax_referer('swiftype-ajax-nonce');
     125
    109126        $this->getConfig()->reset();
    110127        $this->getConfig()->setApiKey(trim($_POST['api_key']));
     
    126143    public function createEngine()
    127144    {
     145        \check_ajax_referer('swiftype-ajax-nonce');
     146
    128147        $this->getConfig()->setLanguage(isset($_POST['language']) ? $_POST['language'] : null);
    129148        $this->getConfig()->setEngineSlug(trim($_POST['engine_name']));
     
    143162    public function clearConfig()
    144163    {
     164        \check_ajax_referer('swiftype-ajax-nonce');
     165
    145166        $this->getConfig()->reset();
    146167        $this->redirect();
  • swiftype-search/trunk/Admin/Page.php

    r2056911 r2174745  
    4949    {
    5050        parent::__construct();
     51
    5152        \add_action('admin_menu', [$this, 'addMenu']);
    5253        \add_action('admin_enqueue_scripts', [$this, 'enqueueAdminAssets']);
     
    6364    public function getContent()
    6465    {
    65         $isAuth = $this->getConfig()->getApiKey() && $this->getClient() !== null;
     66        if (\current_user_can('manage_options')) {
     67            $isAuth = $this->getConfig()->getApiKey() && $this->getClient() !== null;
    6668
    67         if($this->error) {
    68             $this->renderTemplate('error.php');
    69         } else if (!$isAuth) {
    70             $this->renderTemplate('authorize.php');
    71         } else if (!$this->getConfig()->getEngineSlug() || null === $this->engine) {
    72             $this->renderTemplate('choose-engine.php');
    73         } else {
    74             $this->renderTemplate('controls.php');
     69            if($this->error) {
     70                $this->renderTemplate('error.php');
     71            } else if (!$isAuth) {
     72                $this->renderTemplate('authorize.php');
     73            } else if (!$this->getConfig()->getEngineSlug() || null === $this->engine) {
     74                $this->renderTemplate('choose-engine.php');
     75            } else {
     76                $this->renderTemplate('controls.php');
     77            }
    7578        }
    7679    }
     
    9093    public function addMenu()
    9194    {
    92         \add_menu_page(self::MENU_TITLE, SELF::MENU_TITLE, 'manage_options', SELF::MENU_SLUG, [$this, 'getContent'], $this->getIconUrl());
     95        if (\current_user_can('manage_options')) {
     96          \add_menu_page(self::MENU_TITLE, SELF::MENU_TITLE, 'manage_options', SELF::MENU_SLUG, [$this, 'getContent'], $this->getIconUrl());
     97        }
    9398    }
    9499
  • swiftype-search/trunk/Cli/Command.php

    r2056911 r2174745  
    108108        if ($this->client == null) {
    109109            \WP_CLI::error("Unable to connect to Site Search : check your API key is valid.");
     110        }
     111
     112        if ($this->engine == null) {
     113            \do_action('swiftype_create_engine');
    110114        }
    111115
  • swiftype-search/trunk/Document/Indexer.php

    r2056911 r2174745  
    3232    public function installHooks()
    3333    {
    34         \add_action('future_to_publish', [$this, 'handleFutureToPublish']);
    35 
    36         foreach ($this->getConfig()->allowedPostTypes() as $postType) {
    37             \add_action("rest_after_insert_{$postType}", [$this, 'handleRestUpdatePost']);
    38         }
    39 
    40         \add_action('save_post', [$this, 'handleSavePost'], 99, 1);
    41 
    42         \add_action('transition_post_status', [$this, 'handleTransitionPostStatus'], 99, 3);
    43         \add_action('trashed_post', [$this, 'handleTrashedPost']);
    44 
    45 
    46         add_action('swiftype_batch_post_index', [$this, 'handlePostBatchIndex']);
    47         add_action('swiftype_batch_post_delete', [$this, 'handlePostBatchDelete']);
     34        if (\current_user_can('edit_posts') || $this->isWpCLI()) {
     35          \add_action('future_to_publish', [$this, 'handleFutureToPublish']);
     36
     37          foreach ($this->getConfig()->allowedPostTypes() as $postType) {
     38              \add_action("rest_after_insert_{$postType}", [$this, 'handleRestUpdatePost']);
     39          }
     40
     41          \add_action('save_post', [$this, 'handleSavePost'], 99, 1);
     42
     43          \add_action('transition_post_status', [$this, 'handleTransitionPostStatus'], 99, 3);
     44          \add_action('trashed_post', [$this, 'handleTrashedPost']);
     45
     46
     47          add_action('swiftype_batch_post_index', [$this, 'handlePostBatchIndex']);
     48          add_action('swiftype_batch_post_delete', [$this, 'handlePostBatchDelete']);
     49        }
    4850    }
    4951
  • swiftype-search/trunk/Engine/Manager.php

    r2056911 r2174745  
    2020        parent::__construct();
    2121
     22        if ($this->isWpCLI()) {
     23            $this->installHooks();
     24        }
     25
     26        \add_action('admin_init', function() {
     27          if (\current_user_can('manage_options')) {
     28              $this->installHooks();
     29          }
     30        });
     31
     32        \add_action('swiftype_client_loaded', [$this, 'loadEngine']);
     33    }
     34
     35    /**
     36     * Install hooks for the admin actions.
     37     */
     38    public function installHooks() {
    2239        \add_action('swiftype_create_engine', [$this, 'createEngine']);
    23         \add_action('swiftype_client_loaded', [$this, 'loadEngine']);
    2440        \add_action('wp_ajax_check_engine_exists', [$this, 'asyncCheckEngineExists']);
    2541    }
     
    4258
    4359        $language = $this->getConfig()->getLanguage();
     60
    4461        $engine = $this->getClient()->createEngine($engineSlug, $language);
    4562        $this->getConfig()->setEngineSlug($engine['slug']);
  • swiftype-search/trunk/README.txt

    r2061675 r2174745  
    44Tags: search, better search, custom search, relevant search, search by category, autocomplete, suggest, typeahead
    55Requires at least: 3.3
    6 Tested up to: 5.1.0
    7 Stable tag: 2.0.1
     6Tested up to: 5.2.4
     7Stable tag: 2.0.2
    88License: Apache 2.0
    99License URI: https://github.com/swiftype/swiftype-wordpress/blob/master/LICENSE
     
    6666
    6767== Changelog ==
     68
     69= 2.0.2 =
     70* WP-CLI fixes and action refactoring
    6871
    6972= 2.0.1 =
  • swiftype-search/trunk/scripts/publish.sh

    r795116 r2174745  
    3232echo " done"
    3333
    34 echo -n "Copying current git state to svn trunk..."
     34echo -n "Copying current git state to svn assets & trunk..."
    3535find $svn_directory/trunk -type lf ! -path '*.svn*' -exec rm {} \;
     36cp $git_directory/assets/banner-* $git_directory/assets/screenshot-* $svn_directory/assets
    3637cp -R $git_directory/* $svn_directory/trunk/
    3738cd $svn_directory
  • swiftype-search/trunk/swiftype.php

    r2061691 r2174745  
    1010*/
    1111
    12 define('SWIFTYPE_VERSION', '2.0.1');
     12define('SWIFTYPE_VERSION', '2.0.2');
    1313
    1414require_once('vendor/autoload.php');
  • swiftype-search/trunk/templates/admin/authorize.php

    r2056911 r2174745  
    4141                <p><?= __("Enter your API key in the field below and click 'Authorize' to get started."); ?></p>
    4242                <form name="swiftype_settings" method="post" action="<?php echo \esc_url(\admin_url()); ?>">
    43                     <?php wp_nonce_field('swiftype-nonce'); ?>
     43                    <?php wp_nonce_field('swiftype-ajax-nonce'); ?>
    4444                    <input type="hidden" name="action" value="swiftype_set_api_key">
    4545                    <ul>
  • swiftype-search/trunk/templates/admin/choose-engine.php

    r2061670 r2174745  
    1212            <div class="card">
    1313                <form name="swiftype_settings" id="engine-chooser-form" method="post" action="<?php echo \esc_url(\admin_url()); ?>">
    14                     <?php wp_nonce_field('swiftype-nonce'); ?>
     14                    <?php wp_nonce_field('swiftype-ajax-nonce'); ?>
    1515                    <input type="hidden" name="action" value="swiftype_create_engine">
    1616                    <?php if (isset($_REQUEST['error'])): ?>
     
    8383
    8484    <form name="swiftype_reset" method="post" action="<?php echo \esc_url(\admin_url()); ?>">
    85         <?php wp_nonce_field('swiftype-nonce'); ?>
     85        <?php wp_nonce_field('swiftype-ajax-nonce'); ?>
    8686        <input type="hidden" name="action" value="swiftype_clear_config">
    8787    </form>
  • swiftype-search/trunk/templates/admin/controls/dangerous-settings.php

    r2056911 r2174745  
    99            <td>
    1010            <form name="swiftype_settings_reset" method="post" action="<?php echo \esc_url(\admin_url()); ?>">
    11                 <?php wp_nonce_field('swiftype-nonce'); ?>
     11                <?php wp_nonce_field('swiftype-ajax-nonce'); ?>
    1212                <input type="hidden" name="action" value="swiftype_clear_config">
    1313                <input type="submit" name="Submit" value="Reset Configuration"  class="button-primary" />
  • swiftype-search/trunk/tests/bootstrap.php

    r2056911 r2174745  
    2626    require_once dirname(dirname(__FILE__)) . '/swiftype.php';
    2727}
     28
    2829tests_add_filter('muplugins_loaded', '_manually_load_plugin');
    2930
    3031// Start up the WP testing environment.
    3132require $testsDir . '/includes/bootstrap.php';
    32 
Note: See TracChangeset for help on using the changeset viewer.