Plugin Directory

Changeset 1839036


Ignore:
Timestamp:
03/13/2018 12:15:38 AM (8 years ago)
Author:
wpdashboard
Message:

adding in things for 1.1.18

Location:
wp-dashboard/trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • wp-dashboard/trunk/api/class-wpdashboard-api.php

    r1824829 r1839036  
    2525 */
    2626
    27 require_once 'class-wpdashboard-api-base.php';
    2827require_once 'lib/class-wpdashboard-upgrade.php';
    2928require_once 'lib/class-wpdashboard-gravity-forms.php';
    30 require_once 'lib/class-wpdashboard-plugins.php';
    3129
    3230class Wpdashboard_Api {
     
    4947     */
    5048    private $version;
     49
     50    /**
     51     * The request made to the API.
     52     *
     53     * @since    1.0.0
     54     * @access   private
     55     * @var      string    $request_type    The current request made to the API.
     56     */
     57    private $request_type;
    5158
    5259    /**
     
    175182                $home_url_parsed = parse_url($home_url);
    176183                $klein = new \Klein\Klein();
    177                 $klein->respond('GET', (isset($home_url_parsed['path'])?$home_url_parsed['path']:'') . '/wp-dashboard/api/[*:api_key]/[connect-site|check-plugins|check-themes|check-wordpress|get-users|update-plugin|generate-login-url|auto-login|set-admin-user|update-all-plugins|delete-site|add-redirect|remove-redirect|check-wpdashboard-updates|gravity-forms|add-tag-manager:action]', function ($request, $response) {
     184                $actions = [
     185                    'connect-site',
     186                    'check-plugins',
     187                    'check-themes',
     188                    'check-wordpress',
     189                    'get-users',
     190                    'update-plugin',
     191                    'generate-login-url',
     192                    'auto-login',
     193                    'set-admin-user',
     194                    'update-all-plugins',
     195                    'delete-site',
     196                    'add-redirect',
     197                    'remove-redirect',
     198                    'check-wpdashboard-updates',
     199                    'gravity-forms',
     200                    'add-tag-manager',
     201                    'update-core',
     202                    'add-hubspot-id',
     203                    'update-user',
     204                    'get-pages',
     205                    'get-posts',
     206                    'get-comments',
     207                ];
     208                $klein->respond('GET', (isset($home_url_parsed['path'])?$home_url_parsed['path']:'') . '/wp-dashboard/api/[*:api_key]/['. implode('|', $actions) . ':action]', function ($request, $response) {
    178209                    if ($request->api_key == $this->get_option('api_key')) {
    179210                        $user = $this->get_admin_user();
     
    239270                            case 'add-tag-manager':
    240271                                $this->add_tag_manager($request, $response);
     272                                break;
     273                            case 'update-core':
     274                                $this->update_core($request, $response);
     275                                break;
     276                            case 'add-hubspot-id':
     277                                $this->add_hubspot_id($request, $response);
     278                                break;
     279                            case 'update-user':
     280                                $this->update_user($request, $response);
     281                                break;
     282                            case 'get-pages':
     283                                $this->check_pages($request, $response);
     284                                break;
     285                            case 'get-posts':
     286                                $this->check_posts($request, $response);
     287                                break;
     288                            case 'get-comments':
     289                                $this->check_comments($request, $response);
    241290                                break;
    242291                        }
     
    368417
    369418    /**
     419     * Update Plugin.
     420     *
     421     * @since    1.0.0
     422     *
     423     * @param $request
     424     * @param $response
     425     */
     426    public function update_plugin($request, $response) {
     427        $result = $this->upgrade_client->upgrade_plugin($request->param('plugin'));
     428        $resp['updated'] = $result;
     429        $this->respond($response, $resp);
     430    }
     431
     432    /**
     433     * Update All Plugins.
     434     *
     435     * @since    1.0.0
     436     *
     437     * @param $request
     438     * @param $response
     439     */
     440    public function update_all_plugins($request, $response) {
     441        $result = $this->upgrade_client->upgrade_all_plugins();
     442        $resp['updated'] = $result;
     443        $this->respond($response, $resp);
     444    }
     445
     446    /**
    370447     * Generate Login URL.
    371448     *
     
    526603
    527604    /**
     605     * Add Hubspot ID
     606     *
     607     * @since    1.0.110
     608     *
     609     * @param $request
     610     * @param $response
     611     */
     612    public function add_hubspot_id($request, $response) {
     613        $this->update_option('hubspot_id', $request->param('hubspot_id'), false);
     614        $this->respond($response);
     615    }
     616
     617    /**
     618     * Update Core
     619     *
     620     * Update the installed core for the site
     621     *
     622     * @since 1.0.0
     623     *
     624     * @param $request
     625     * @param $response
     626     * @return false|null|string|WP_Error
     627     */
     628    public function update_core($request, $response) {
     629        if(!function_exists('find_core_update')) {
     630            require_once ABSPATH . '/wp-admin/includes/update.php';
     631        }
     632        $update_available = find_core_update(get_bloginfo('version'), get_bloginfo('language'));
     633        if(!$update_available) {
     634            return $this->respond($response, [
     635                'updated' => false,
     636                'version' => get_bloginfo('version'),
     637            ], true);
     638        } else {
     639            $upgrader = new Core_Upgrader();
     640            $update = $upgrader->upgrade($update_available);
     641            if(is_wp_error($update)) {
     642                return $update;
     643            } else {
     644                return $this->respond($response, [
     645                    'updated' => true,
     646                    'version' => get_bloginfo('version')
     647                ], true);
     648            }
     649        }
     650    }
     651
     652    /**
     653     * Update User
     654     *
     655     * @since    1.1.18
     656     *
     657     * @param $request
     658     * @param $response
     659     * @return int|WP_Error
     660     */
     661    public function update_user($request, $response) {
     662        $user = get_user_by('ID', $request->param('user_id'));
     663
     664        if($nicename = $request->param('user_email'))
     665            $user->user_email = $request->param('user_email');
     666
     667        if($nicename = $request->param('user_url'))
     668            $user->user_url = $request->param('user_url');
     669
     670        if($nicename = $request->param('display_name'))
     671            $user->display_name = $request->param('display_name');
     672
     673        $update = wp_update_user($user);
     674        if(is_wp_error($update)) {
     675            return $update;
     676        } else {
     677            $this->respond($response, [
     678                'user_id' => $user,
     679                'updated' => true
     680            ]);
     681        }
     682    }
     683
     684    /**
     685     * Check Pages
     686     *
     687     * @since    1.1.18
     688     *
     689     * @param $request
     690     * @param $response
     691     * @return void
     692     */
     693    public function check_pages($request, $response) {
     694        $pages = get_pages();
     695        $this->respond($response, $pages);
     696    }
     697
     698    /**
     699     * Check Posts
     700     *
     701     * @since    1.1.18
     702     *
     703     * @param $request
     704     * @param $response
     705     * @return void
     706     */
     707    public function check_posts($request, $response) {
     708        $pages = get_posts();
     709        $this->respond($response, $pages);
     710    }
     711
     712    /**
     713     * Check Comments
     714     *
     715     * @since    1.1.18
     716     *
     717     * @param $request
     718     * @param $response
     719     * @return void
     720     */
     721    public function check_comments($request, $response) {
     722        $pages = get_comments();
     723        $this->respond($response, $pages);
     724    }
     725
     726    /**
    528727     * Get gravity forms instance.
    529728     *
  • wp-dashboard/trunk/api/lib/class-wpdashboard-upgrade.php

    r1824829 r1839036  
    105105            }
    106106        }
    107         if(!$resp = $this->do_plugin_upgrade($upgrader, $file, $info)) {
    108             return $resp;
    109         } else {
    110             $resp = array_merge($resp, [$file => $skin->result]);
    111             return $resp;
    112         }
     107        $this->do_plugin_upgrade($upgrader, $file, $info);
     108        $resp = array_merge($resp, [$file => $skin->result]);
     109        return $resp;
    113110    }
    114111
  • wp-dashboard/trunk/includes/class-wpdashboard-loader.php

    r1824829 r1839036  
    4242    protected $filters;
    4343
    44     protected $routes;
    45 
    4644    /**
    4745     * Initialize the collections used to maintain the actions and filters.
     
    5351        $this->actions = array();
    5452        $this->filters = array();
    55         $this->routes = array();
    5653
    5754    }
    5855
    59     /**
    60      * Add a new action to the collection to be registered with WordPress.
    61      *
    62      * @since    1.0.0
    63      * @param    string               $hook             The name of the WordPress action that is being registered.
    64      * @param    object               $component        A reference to the instance of the object on which the action is defined.
    65      * @param    string               $callback         The name of the function definition on the $component.
    66      * @param    int                  $priority         Optional. The priority at which the function should be fired. Default is 10.
    67      * @param    int                  $accepted_args    Optional. The number of arguments that should be passed to the $callback. Default is 1.
    68      */
    69     public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
    70         $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
    71     }
    72 
    73     /**
    74      * Add a new rest route to the collection to be registered with WordPress.
    75      *
    76      * @since    1.0.0
    77      * @param    string               $hook             The name of the WordPress action that is being registered.
    78      * @param    object               $component        A reference to the instance of the object on which the action is defined.
    79      * @param    string               $callback         The name of the function definition on the $component.
    80      * @param    int                  $priority         Optional. The priority at which the function should be fired. Default is 10.
    81      * @param    int                  $accepted_args    Optional. The number of arguments that should be passed to the $callback. Default is 1.
    82      */
    83     public function add_rest_route( $namespace, $route, $methods, $callback ) {
    84         $this->routes[] = [
    85             'namespace' => $namespace,
    86             'route' => $route,
    87             'methods' => $methods,
    88             'callback' => $callback
    89         ];
    90     }
     56    /**
     57     * Add a new action to the collection to be registered with WordPress.
     58     *
     59     * @since    1.0.0
     60     * @param    string               $hook             The name of the WordPress action that is being registered.
     61     * @param    object               $component        A reference to the instance of the object on which the action is defined.
     62     * @param    string               $callback         The name of the function definition on the $component.
     63     * @param    int                  $priority         Optional. The priority at which the function should be fired. Default is 10.
     64     * @param    int                  $accepted_args    Optional. The number of arguments that should be passed to the $callback. Default is 1.
     65     */
     66    public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
     67        $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
     68    }
    9169
    9270    /**
     
    147125        }
    148126
    149         foreach($this->routes AS $route) {
    150             add_action('rest_api_init', function () use($route) {
    151                 register_rest_route( $route['namespace'], $route['route'], array(
    152                     'methods' => $route['methods'],
    153                     'callback' => $route['callback'],
    154                 ));
    155             });
    156         }
    157 
    158127    }
    159128
  • wp-dashboard/trunk/includes/class-wpdashboard.php

    r1824829 r1839036  
    196196    private function define_api_hooks() {
    197197
    198         $plugin_api = new WpDashboard_Api_Plugins( $this->get_plugin_name(), $this->get_version() );
    199         $this->loader->add_rest_route('wp-dashboard/v1', 'plugins', 'GET', [$plugin_api, 'get_all_plugins']);
    200         $this->loader->add_rest_route('wp-dashboard/v1', 'plugins/install', 'POST', [$plugin_api, 'install_plugin']);
    201         $this->loader->add_rest_route('wp-dashboard/v1', 'plugins/update', 'POST', [$plugin_api, 'update_plugin']);
    202         $this->loader->add_rest_route('wp-dashboard/v1', 'plugins/activate', 'PUT', [$plugin_api, 'activate_plugin']);
    203         $this->loader->add_rest_route('wp-dashboard/v1', 'plugins/deactivate', 'PUT', [$plugin_api, 'deactivate_plugin']);
    204         $this->loader->add_rest_route('wp-dashboard/v1', 'plugins/delete', 'DELETE', [$plugin_api, 'delete_plugin']);
     198        $plugin_api = new Wpdashboard_Api( $this->get_plugin_name(), $this->get_version() );
     199
     200        $this->loader->add_action( 'parse_request', $plugin_api, 'detect_api_request' );
     201
     202        $this->loader->add_action( 'parse_request', $plugin_api, 'detect_redirects' );
    205203
    206204    }
     
    219217        $this->loader->add_action( 'wp_enqueue_styles', $plugin_public, 'enqueue_styles' );
    220218        $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' );
     219
    221220    }
    222221
  • wp-dashboard/trunk/public/class-wpdashboard-public.php

    r1821560 r1839036  
    126126                }
    127127            });
     128
     129            if($this->get_option('hubspot_id')) {
     130                wp_enqueue_script( 'hubspot-tracking-script', '//js.hs-scripts.com/' . $this->get_option('hubspot_id') . '.js', [], false, true );
     131            }
     132
     133            add_filter('script_loader_tag', array($this, 'asyncDeferScript'), 10, 2);
    128134        }
     135    }
    129136
     137    public function asyncDeferScript($tag, $handle) {
     138
     139        if ($handle == 'hubspot-tracking-script') {
     140            return str_replace(' src', ' async defer src', $tag);
     141        } else {
     142            return $tag;
     143        }
    130144    }
    131145
  • wp-dashboard/trunk/readme.txt

    r1824829 r1839036  
    66Tested up to: 4.9.1
    77Requires PHP: 5.6
    8 Stable tag: 1.1.17
     8Stable tag: 1.1.18
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    3535    See your errors, and organic rankings. See what you can do to modify and improve your search results.
    3636
    37 * Hubspot (coming soon)
    38     Gravity forms straight to Hubspot, or view your Hubspot information next to form submissions. Easily setup the tracking code, again, without modifying the themes.
     37* HubSpot
     38    Connecting HubSpot sets up the tracking script automatically. No configuration required.
    3939
    4040* Slack (coming soon)
     
    5454
    5555== Changelog ==
     56
     57= 1.1.18 =
     58* Added HubSpot integration.
     59* Added Gathering of Pages, Posts, and Comments
    5660
    5761= 1.1.17 =
Note: See TracChangeset for help on using the changeset viewer.