����JFIF���������
__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
<?php
namespace WordPressPopularPosts\Rest;
use WordPressPopularPosts\{ Output, Translate };
use WordPressPopularPosts\Traits\QueriesPosts;
class WidgetEndpoint extends Endpoint {
use QueriesPosts;
/**
* Output object.
*
* @var \WordPressPopularPosts\Output $output
* @access private
*/
protected $output;
/**
* Initializes class.
*
* @param array
* @param \WordPressPopularPosts\Translate
* @param \WordPressPopularPosts\Output
*/
public function __construct(array $config, Translate $translate, Output $output)
{
$this->config = $config;
$this->translate = $translate;
$this->output = $output;
}
/**
* Registers the endpoint(s).
*
* @since 5.3.0
*/
public function register()
{
$version = '2';
$namespace = 'wordpress-popular-posts/v' . $version;
register_rest_route($namespace, '/widget/', [
[
'methods' => 'POST',
'callback' => [$this, 'get_widget_block'],
'permission_callback' => '__return_true',
'args' => $this->get_widget_params(),
]
]);
}
/**
* Retrieves a popular posts widget for display.
*
* @since 5.4.0
*
* @param \WP_REST_Request $request Full details about the request.
* @return \WP_Error|\WP_REST_Response Response object on success, or WP_Error object on failure.
*/
public function get_widget_block($request)
{
$instance = $request->get_params();
$is_single = $request->get_param('is_single');
$lang = $request->get_param('lang');
// Multilang support
$this->set_lang($lang);
$popular_posts = $this->maybe_query($instance);
if ( is_numeric($is_single) && $is_single > 0 ) {
add_filter('wpp_is_single', function($id) use ($is_single) {
return $is_single;
});
}
$this->output->set_data($popular_posts->get_posts());
$this->output->set_public_options($instance);
$this->output->build_output();
return [
'widget' => ( $this->config['tools']['cache']['active'] ? '<!-- cached -->' : '' ) . $this->output->get_output()
];
}
/**
* Retrieves the query params for getting a widget instance.
*
* @since 4.1.0
*
* @return array Query parameters for getting a widget instance.
*/
public function get_widget_params()
{
return [
'is_single' => [
'type' => 'integer',
'default' => null,
'sanitize_callback' => 'absint'
],
'lang' => [
'type' => 'string',
'default' => null,
'sanitize_callback' => 'sanitize_text_field'
],
];
}
}
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| Controller.php | File | 2.66 KB | 0644 |
|
| Endpoint.php | File | 1.75 KB | 0644 |
|
| PostsEndpoint.php | File | 8.65 KB | 0644 |
|
| TaxonomiesEndpoint.php | File | 1.03 KB | 0644 |
|
| ThemesEndpoint.php | File | 1.66 KB | 0644 |
|
| ThumbnailsEndpoint.php | File | 1.95 KB | 0644 |
|
| ViewLoggerEndpoint.php | File | 13.04 KB | 0644 |
|
| WidgetEndpoint.php | File | 3.02 KB | 0644 |
|