@@ -6,79 +6,79 @@ |
||
6 | 6 | |
7 | 7 | class Import_Page extends Wordlift_Admin_Page { |
8 | 8 | |
9 | - /** |
|
10 | - * {@inheritdoc} |
|
11 | - */ |
|
12 | - public function get_page_title() { |
|
13 | - |
|
14 | - return __( 'Google Addon Import', 'wordlift' ); |
|
15 | - } |
|
16 | - |
|
17 | - /** |
|
18 | - * {@inheritdoc} |
|
19 | - */ |
|
20 | - public function get_menu_title() { |
|
21 | - |
|
22 | - return __( 'Google Addon Import', 'wordlift' ); |
|
23 | - } |
|
24 | - |
|
25 | - protected function get_parent_slug() { |
|
26 | - return null; |
|
27 | - } |
|
28 | - |
|
29 | - public function render() { |
|
30 | - |
|
31 | - wp_enqueue_script( |
|
32 | - 'wl-gaddon-import-page', |
|
33 | - plugin_dir_url( __FILE__ ) . 'assets/gaddon-import-page.js', |
|
34 | - array(), |
|
35 | - WORDLIFT_VERSION, |
|
36 | - false |
|
37 | - ); |
|
38 | - |
|
39 | - wp_localize_script( |
|
40 | - 'wl-gaddon-import-page', |
|
41 | - '_wlGaddonImportSettings', |
|
42 | - array( |
|
43 | - 'restUrl' => get_rest_url(), |
|
44 | - 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
45 | - 'entityUrls' => $this->get_entity_urls(), |
|
46 | - ) |
|
47 | - ); |
|
48 | - |
|
49 | - parent::render(); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * {@inheritdoc} |
|
54 | - */ |
|
55 | - public function get_menu_slug() { |
|
56 | - |
|
57 | - return 'wl_google_addon_import'; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * {@inheritdoc} |
|
62 | - */ |
|
63 | - public function get_partial_name() { |
|
64 | - return 'wordlift-admin-google-addon-import.php'; |
|
65 | - } |
|
66 | - |
|
67 | - private function get_entity_urls() { |
|
68 | - if ( isset( $_GET['e'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
69 | - return array(); |
|
70 | - } |
|
71 | - |
|
72 | - $entities = esc_url_raw( wp_unslash( $_GET['e'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
73 | - |
|
74 | - if ( empty( $entities ) ) { |
|
75 | - return array(); |
|
76 | - } |
|
77 | - if ( ! is_string( $entities ) ) { |
|
78 | - return array(); |
|
79 | - } |
|
80 | - |
|
81 | - return explode( ',', $entities ); |
|
82 | - } |
|
9 | + /** |
|
10 | + * {@inheritdoc} |
|
11 | + */ |
|
12 | + public function get_page_title() { |
|
13 | + |
|
14 | + return __( 'Google Addon Import', 'wordlift' ); |
|
15 | + } |
|
16 | + |
|
17 | + /** |
|
18 | + * {@inheritdoc} |
|
19 | + */ |
|
20 | + public function get_menu_title() { |
|
21 | + |
|
22 | + return __( 'Google Addon Import', 'wordlift' ); |
|
23 | + } |
|
24 | + |
|
25 | + protected function get_parent_slug() { |
|
26 | + return null; |
|
27 | + } |
|
28 | + |
|
29 | + public function render() { |
|
30 | + |
|
31 | + wp_enqueue_script( |
|
32 | + 'wl-gaddon-import-page', |
|
33 | + plugin_dir_url( __FILE__ ) . 'assets/gaddon-import-page.js', |
|
34 | + array(), |
|
35 | + WORDLIFT_VERSION, |
|
36 | + false |
|
37 | + ); |
|
38 | + |
|
39 | + wp_localize_script( |
|
40 | + 'wl-gaddon-import-page', |
|
41 | + '_wlGaddonImportSettings', |
|
42 | + array( |
|
43 | + 'restUrl' => get_rest_url(), |
|
44 | + 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
45 | + 'entityUrls' => $this->get_entity_urls(), |
|
46 | + ) |
|
47 | + ); |
|
48 | + |
|
49 | + parent::render(); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * {@inheritdoc} |
|
54 | + */ |
|
55 | + public function get_menu_slug() { |
|
56 | + |
|
57 | + return 'wl_google_addon_import'; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * {@inheritdoc} |
|
62 | + */ |
|
63 | + public function get_partial_name() { |
|
64 | + return 'wordlift-admin-google-addon-import.php'; |
|
65 | + } |
|
66 | + |
|
67 | + private function get_entity_urls() { |
|
68 | + if ( isset( $_GET['e'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
69 | + return array(); |
|
70 | + } |
|
71 | + |
|
72 | + $entities = esc_url_raw( wp_unslash( $_GET['e'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
73 | + |
|
74 | + if ( empty( $entities ) ) { |
|
75 | + return array(); |
|
76 | + } |
|
77 | + if ( ! is_string( $entities ) ) { |
|
78 | + return array(); |
|
79 | + } |
|
80 | + |
|
81 | + return explode( ',', $entities ); |
|
82 | + } |
|
83 | 83 | |
84 | 84 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | */ |
12 | 12 | public function get_page_title() { |
13 | 13 | |
14 | - return __( 'Google Addon Import', 'wordlift' ); |
|
14 | + return __('Google Addon Import', 'wordlift'); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function get_menu_title() { |
21 | 21 | |
22 | - return __( 'Google Addon Import', 'wordlift' ); |
|
22 | + return __('Google Addon Import', 'wordlift'); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | protected function get_parent_slug() { |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | wp_enqueue_script( |
32 | 32 | 'wl-gaddon-import-page', |
33 | - plugin_dir_url( __FILE__ ) . 'assets/gaddon-import-page.js', |
|
33 | + plugin_dir_url(__FILE__).'assets/gaddon-import-page.js', |
|
34 | 34 | array(), |
35 | 35 | WORDLIFT_VERSION, |
36 | 36 | false |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | '_wlGaddonImportSettings', |
42 | 42 | array( |
43 | 43 | 'restUrl' => get_rest_url(), |
44 | - 'nonce' => wp_create_nonce( 'wp_rest' ), |
|
44 | + 'nonce' => wp_create_nonce('wp_rest'), |
|
45 | 45 | 'entityUrls' => $this->get_entity_urls(), |
46 | 46 | ) |
47 | 47 | ); |
@@ -65,20 +65,20 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | private function get_entity_urls() { |
68 | - if ( isset( $_GET['e'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
68 | + if (isset($_GET['e'])) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
69 | 69 | return array(); |
70 | 70 | } |
71 | 71 | |
72 | - $entities = esc_url_raw( wp_unslash( $_GET['e'] ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
72 | + $entities = esc_url_raw(wp_unslash($_GET['e'])); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
73 | 73 | |
74 | - if ( empty( $entities ) ) { |
|
74 | + if (empty($entities)) { |
|
75 | 75 | return array(); |
76 | 76 | } |
77 | - if ( ! is_string( $entities ) ) { |
|
77 | + if ( ! is_string($entities)) { |
|
78 | 78 | return array(); |
79 | 79 | } |
80 | 80 | |
81 | - return explode( ',', $entities ); |
|
81 | + return explode(',', $entities); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | } |
@@ -11,17 +11,17 @@ |
||
11 | 11 | */ |
12 | 12 | class Loader extends Default_Loader { |
13 | 13 | |
14 | - public function init_all_dependencies() { |
|
15 | - new Import_Page(); |
|
16 | - $rest_endpoint = new Rest_Endpoint(); |
|
17 | - $rest_endpoint->init(); |
|
18 | - } |
|
14 | + public function init_all_dependencies() { |
|
15 | + new Import_Page(); |
|
16 | + $rest_endpoint = new Rest_Endpoint(); |
|
17 | + $rest_endpoint->init(); |
|
18 | + } |
|
19 | 19 | |
20 | - public function get_feature_slug() { |
|
21 | - return 'google-addon-integration'; |
|
22 | - } |
|
20 | + public function get_feature_slug() { |
|
21 | + return 'google-addon-integration'; |
|
22 | + } |
|
23 | 23 | |
24 | - public function get_feature_default_value() { |
|
25 | - return true; |
|
26 | - } |
|
24 | + public function get_feature_default_value() { |
|
25 | + return true; |
|
26 | + } |
|
27 | 27 | } |
@@ -8,61 +8,61 @@ |
||
8 | 8 | |
9 | 9 | class Rest_Endpoint { |
10 | 10 | |
11 | - public function init() { |
|
12 | - // PHP 5.3 compatibility. |
|
13 | - $that = $this; |
|
11 | + public function init() { |
|
12 | + // PHP 5.3 compatibility. |
|
13 | + $that = $this; |
|
14 | 14 | |
15 | - add_action( |
|
16 | - 'rest_api_init', |
|
17 | - function () use ( $that ) { |
|
18 | - register_rest_route( |
|
19 | - WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
20 | - '/gaddon/import-entity', |
|
21 | - array( |
|
22 | - 'methods' => \WP_REST_Server::CREATABLE, |
|
23 | - 'callback' => array( $that, 'import_entity' ), |
|
24 | - 'permission_callback' => function () { |
|
25 | - return current_user_can( 'manage_options' ); |
|
26 | - }, |
|
27 | - 'args' => array( |
|
28 | - 'id' => array( |
|
29 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
30 | - 'validate_callback' => function ( $param, $request, $key ) { |
|
31 | - return is_string( $param ); |
|
32 | - }, |
|
33 | - ), |
|
34 | - ), |
|
35 | - ) |
|
36 | - ); |
|
37 | - } |
|
38 | - ); |
|
39 | - } |
|
15 | + add_action( |
|
16 | + 'rest_api_init', |
|
17 | + function () use ( $that ) { |
|
18 | + register_rest_route( |
|
19 | + WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
20 | + '/gaddon/import-entity', |
|
21 | + array( |
|
22 | + 'methods' => \WP_REST_Server::CREATABLE, |
|
23 | + 'callback' => array( $that, 'import_entity' ), |
|
24 | + 'permission_callback' => function () { |
|
25 | + return current_user_can( 'manage_options' ); |
|
26 | + }, |
|
27 | + 'args' => array( |
|
28 | + 'id' => array( |
|
29 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
30 | + 'validate_callback' => function ( $param, $request, $key ) { |
|
31 | + return is_string( $param ); |
|
32 | + }, |
|
33 | + ), |
|
34 | + ), |
|
35 | + ) |
|
36 | + ); |
|
37 | + } |
|
38 | + ); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param $request \WP_REST_Request |
|
43 | - * |
|
44 | - * @return bool[] |
|
45 | - */ |
|
46 | - public function import_entity( $request ) { |
|
41 | + /** |
|
42 | + * @param $request \WP_REST_Request |
|
43 | + * |
|
44 | + * @return bool[] |
|
45 | + */ |
|
46 | + public function import_entity( $request ) { |
|
47 | 47 | |
48 | - $body = $request->get_body(); |
|
49 | - $data = json_decode( $body, true ); |
|
50 | - $entity_id = $data['entity_id']; |
|
48 | + $body = $request->get_body(); |
|
49 | + $data = json_decode( $body, true ); |
|
50 | + $entity_id = $data['entity_id']; |
|
51 | 51 | |
52 | - $content_service = Wordpress_Content_Service::get_instance(); |
|
52 | + $content_service = Wordpress_Content_Service::get_instance(); |
|
53 | 53 | |
54 | - // Do not create/update an existing entity. |
|
55 | - if ( $content_service->get_by_entity_id_or_same_as( $entity_id ) ) { |
|
56 | - return array( 'import_status' => false ); |
|
57 | - } |
|
54 | + // Do not create/update an existing entity. |
|
55 | + if ( $content_service->get_by_entity_id_or_same_as( $entity_id ) ) { |
|
56 | + return array( 'import_status' => false ); |
|
57 | + } |
|
58 | 58 | |
59 | - $remote_entity = Url_To_Remote_Entity_Converter::convert( $entity_id ); |
|
60 | - $importer = Remote_Entity_Importer_Factory::from_entity( $remote_entity ); |
|
61 | - $result = $importer->import(); |
|
59 | + $remote_entity = Url_To_Remote_Entity_Converter::convert( $entity_id ); |
|
60 | + $importer = Remote_Entity_Importer_Factory::from_entity( $remote_entity ); |
|
61 | + $result = $importer->import(); |
|
62 | 62 | |
63 | - return array( |
|
64 | - 'import_status' => $result ? true : false, |
|
65 | - ); |
|
66 | - } |
|
63 | + return array( |
|
64 | + 'import_status' => $result ? true : false, |
|
65 | + ); |
|
66 | + } |
|
67 | 67 | |
68 | 68 | } |
@@ -14,21 +14,21 @@ discard block |
||
14 | 14 | |
15 | 15 | add_action( |
16 | 16 | 'rest_api_init', |
17 | - function () use ( $that ) { |
|
17 | + function() use ($that) { |
|
18 | 18 | register_rest_route( |
19 | 19 | WL_REST_ROUTE_DEFAULT_NAMESPACE, |
20 | 20 | '/gaddon/import-entity', |
21 | 21 | array( |
22 | 22 | 'methods' => \WP_REST_Server::CREATABLE, |
23 | - 'callback' => array( $that, 'import_entity' ), |
|
24 | - 'permission_callback' => function () { |
|
25 | - return current_user_can( 'manage_options' ); |
|
23 | + 'callback' => array($that, 'import_entity'), |
|
24 | + 'permission_callback' => function() { |
|
25 | + return current_user_can('manage_options'); |
|
26 | 26 | }, |
27 | 27 | 'args' => array( |
28 | 28 | 'id' => array( |
29 | 29 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
30 | - 'validate_callback' => function ( $param, $request, $key ) { |
|
31 | - return is_string( $param ); |
|
30 | + 'validate_callback' => function($param, $request, $key) { |
|
31 | + return is_string($param); |
|
32 | 32 | }, |
33 | 33 | ), |
34 | 34 | ), |
@@ -43,21 +43,21 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @return bool[] |
45 | 45 | */ |
46 | - public function import_entity( $request ) { |
|
46 | + public function import_entity($request) { |
|
47 | 47 | |
48 | 48 | $body = $request->get_body(); |
49 | - $data = json_decode( $body, true ); |
|
49 | + $data = json_decode($body, true); |
|
50 | 50 | $entity_id = $data['entity_id']; |
51 | 51 | |
52 | 52 | $content_service = Wordpress_Content_Service::get_instance(); |
53 | 53 | |
54 | 54 | // Do not create/update an existing entity. |
55 | - if ( $content_service->get_by_entity_id_or_same_as( $entity_id ) ) { |
|
56 | - return array( 'import_status' => false ); |
|
55 | + if ($content_service->get_by_entity_id_or_same_as($entity_id)) { |
|
56 | + return array('import_status' => false); |
|
57 | 57 | } |
58 | 58 | |
59 | - $remote_entity = Url_To_Remote_Entity_Converter::convert( $entity_id ); |
|
60 | - $importer = Remote_Entity_Importer_Factory::from_entity( $remote_entity ); |
|
59 | + $remote_entity = Url_To_Remote_Entity_Converter::convert($entity_id); |
|
60 | + $importer = Remote_Entity_Importer_Factory::from_entity($remote_entity); |
|
61 | 61 | $result = $importer->import(); |
62 | 62 | |
63 | 63 | return array( |
@@ -3,82 +3,82 @@ |
||
3 | 3 | namespace Wordlift\Wordpress; |
4 | 4 | |
5 | 5 | abstract class Submenu_Page_Base implements Page { |
6 | - /** |
|
7 | - * @var string |
|
8 | - */ |
|
9 | - private $menu_slug; |
|
10 | - /** |
|
11 | - * @var string |
|
12 | - */ |
|
13 | - private $page_title; |
|
14 | - /** |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - private $capability; |
|
18 | - /** |
|
19 | - * @var string|null |
|
20 | - */ |
|
21 | - private $parent_slug; |
|
22 | - /** |
|
23 | - * @var string|null |
|
24 | - */ |
|
25 | - private $menu_title; |
|
6 | + /** |
|
7 | + * @var string |
|
8 | + */ |
|
9 | + private $menu_slug; |
|
10 | + /** |
|
11 | + * @var string |
|
12 | + */ |
|
13 | + private $page_title; |
|
14 | + /** |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + private $capability; |
|
18 | + /** |
|
19 | + * @var string|null |
|
20 | + */ |
|
21 | + private $parent_slug; |
|
22 | + /** |
|
23 | + * @var string|null |
|
24 | + */ |
|
25 | + private $menu_title; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Abstract_Submenu_Page constructor. |
|
29 | - * |
|
30 | - * @param string $menu_slug |
|
31 | - * @param string $page_title |
|
32 | - * @param string $capability |
|
33 | - * @param string|null $parent_slug |
|
34 | - * @param string|null $menu_title |
|
35 | - */ |
|
36 | - public function __construct( $menu_slug, $page_title, $capability = 'manage_options', $parent_slug = null, $menu_title = null ) { |
|
27 | + /** |
|
28 | + * Abstract_Submenu_Page constructor. |
|
29 | + * |
|
30 | + * @param string $menu_slug |
|
31 | + * @param string $page_title |
|
32 | + * @param string $capability |
|
33 | + * @param string|null $parent_slug |
|
34 | + * @param string|null $menu_title |
|
35 | + */ |
|
36 | + public function __construct( $menu_slug, $page_title, $capability = 'manage_options', $parent_slug = null, $menu_title = null ) { |
|
37 | 37 | |
38 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
38 | + add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
39 | 39 | |
40 | - $this->menu_slug = $menu_slug; |
|
41 | - $this->page_title = $page_title; |
|
42 | - $this->capability = $capability; |
|
43 | - $this->parent_slug = $parent_slug; |
|
44 | - $this->menu_title = isset( $menu_title ) ? $menu_title : $page_title; |
|
45 | - } |
|
40 | + $this->menu_slug = $menu_slug; |
|
41 | + $this->page_title = $page_title; |
|
42 | + $this->capability = $capability; |
|
43 | + $this->parent_slug = $parent_slug; |
|
44 | + $this->menu_title = isset( $menu_title ) ? $menu_title : $page_title; |
|
45 | + } |
|
46 | 46 | |
47 | - public function get_menu_slug() { |
|
47 | + public function get_menu_slug() { |
|
48 | 48 | |
49 | - return $this->menu_slug; |
|
50 | - } |
|
49 | + return $this->menu_slug; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * The `admin_menu` callback. Will call {@link add_submenu_page} to add the |
|
54 | - * page to the admin menu. |
|
55 | - * |
|
56 | - * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
57 | - * @since 1.0.0 |
|
58 | - */ |
|
59 | - public function admin_menu() { |
|
52 | + /** |
|
53 | + * The `admin_menu` callback. Will call {@link add_submenu_page} to add the |
|
54 | + * page to the admin menu. |
|
55 | + * |
|
56 | + * @return false|string The resulting page's hook_suffix, or false if the user does not have the capability required. |
|
57 | + * @since 1.0.0 |
|
58 | + */ |
|
59 | + public function admin_menu() { |
|
60 | 60 | |
61 | - // Add the sub-menu page. |
|
62 | - // |
|
63 | - // See http://codex.wordpress.org/Function_Reference/add_submenu_page |
|
64 | - $page = add_submenu_page( |
|
65 | - $this->parent_slug, |
|
66 | - $this->page_title, |
|
67 | - $this->menu_title, |
|
68 | - $this->capability, |
|
69 | - $this->menu_slug, |
|
70 | - array( $this, 'render' ) |
|
71 | - ); |
|
61 | + // Add the sub-menu page. |
|
62 | + // |
|
63 | + // See http://codex.wordpress.org/Function_Reference/add_submenu_page |
|
64 | + $page = add_submenu_page( |
|
65 | + $this->parent_slug, |
|
66 | + $this->page_title, |
|
67 | + $this->menu_title, |
|
68 | + $this->capability, |
|
69 | + $this->menu_slug, |
|
70 | + array( $this, 'render' ) |
|
71 | + ); |
|
72 | 72 | |
73 | - // Set a hook to enqueue scripts only when the settings page is displayed. |
|
74 | - add_action( 'admin_print_scripts-' . $page, array( $this, 'enqueue_scripts' ) ); |
|
73 | + // Set a hook to enqueue scripts only when the settings page is displayed. |
|
74 | + add_action( 'admin_print_scripts-' . $page, array( $this, 'enqueue_scripts' ) ); |
|
75 | 75 | |
76 | - // Finally return the page hook_suffix. |
|
77 | - return $page; |
|
78 | - } |
|
76 | + // Finally return the page hook_suffix. |
|
77 | + return $page; |
|
78 | + } |
|
79 | 79 | |
80 | - abstract public function enqueue_scripts(); |
|
80 | + abstract public function enqueue_scripts(); |
|
81 | 81 | |
82 | - abstract public function render(); |
|
82 | + abstract public function render(); |
|
83 | 83 | |
84 | 84 | } |
@@ -33,15 +33,15 @@ discard block |
||
33 | 33 | * @param string|null $parent_slug |
34 | 34 | * @param string|null $menu_title |
35 | 35 | */ |
36 | - public function __construct( $menu_slug, $page_title, $capability = 'manage_options', $parent_slug = null, $menu_title = null ) { |
|
36 | + public function __construct($menu_slug, $page_title, $capability = 'manage_options', $parent_slug = null, $menu_title = null) { |
|
37 | 37 | |
38 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
38 | + add_action('admin_menu', array($this, 'admin_menu')); |
|
39 | 39 | |
40 | 40 | $this->menu_slug = $menu_slug; |
41 | 41 | $this->page_title = $page_title; |
42 | 42 | $this->capability = $capability; |
43 | 43 | $this->parent_slug = $parent_slug; |
44 | - $this->menu_title = isset( $menu_title ) ? $menu_title : $page_title; |
|
44 | + $this->menu_title = isset($menu_title) ? $menu_title : $page_title; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | public function get_menu_slug() { |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | $this->menu_title, |
68 | 68 | $this->capability, |
69 | 69 | $this->menu_slug, |
70 | - array( $this, 'render' ) |
|
70 | + array($this, 'render') |
|
71 | 71 | ); |
72 | 72 | |
73 | 73 | // Set a hook to enqueue scripts only when the settings page is displayed. |
74 | - add_action( 'admin_print_scripts-' . $page, array( $this, 'enqueue_scripts' ) ); |
|
74 | + add_action('admin_print_scripts-'.$page, array($this, 'enqueue_scripts')); |
|
75 | 75 | |
76 | 76 | // Finally return the page hook_suffix. |
77 | 77 | return $page; |
@@ -8,78 +8,78 @@ |
||
8 | 8 | */ |
9 | 9 | class Async_Template_Decorator { |
10 | 10 | |
11 | - /** |
|
12 | - * @var $rest_url_name string |
|
13 | - */ |
|
14 | - private $rest_url_name; |
|
11 | + /** |
|
12 | + * @var $rest_url_name string |
|
13 | + */ |
|
14 | + private $rest_url_name; |
|
15 | 15 | |
16 | - /** |
|
17 | - * @var $filter_name string |
|
18 | - */ |
|
19 | - private $filter_name; |
|
16 | + /** |
|
17 | + * @var $filter_name string |
|
18 | + */ |
|
19 | + private $filter_name; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Async_Template_Decorator constructor. |
|
23 | - * |
|
24 | - * @param $shortcode_instance \Wordlift_Shortcode |
|
25 | - */ |
|
26 | - public function __construct( $shortcode_instance ) { |
|
27 | - $this->rest_url_name = $this->get_widget_name( $shortcode_instance ); |
|
28 | - $this->filter_name = str_replace( '-', '_', $this->rest_url_name ); |
|
29 | - add_action( 'rest_api_init', array( $this, 'register_template_route' ) ); |
|
30 | - } |
|
21 | + /** |
|
22 | + * Async_Template_Decorator constructor. |
|
23 | + * |
|
24 | + * @param $shortcode_instance \Wordlift_Shortcode |
|
25 | + */ |
|
26 | + public function __construct( $shortcode_instance ) { |
|
27 | + $this->rest_url_name = $this->get_widget_name( $shortcode_instance ); |
|
28 | + $this->filter_name = str_replace( '-', '_', $this->rest_url_name ); |
|
29 | + add_action( 'rest_api_init', array( $this, 'register_template_route' ) ); |
|
30 | + } |
|
31 | 31 | |
32 | - public function register_template_route() { |
|
32 | + public function register_template_route() { |
|
33 | 33 | |
34 | - register_rest_route( |
|
35 | - WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
36 | - "/{$this->rest_url_name}/template/", |
|
37 | - array( |
|
38 | - 'methods' => \WP_REST_Server::CREATABLE, |
|
39 | - 'callback' => array( $this, 'get_template' ), |
|
40 | - /** |
|
41 | - * We want this endpoint to be publicly accessible |
|
42 | - */ |
|
43 | - 'permission_callback' => '__return_true', |
|
44 | - 'args' => array( |
|
45 | - 'template_id' => array( |
|
46 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
47 | - 'validate_callback' => function ( $param, $request, $key ) { |
|
48 | - return is_string( $param ) && $param; |
|
49 | - }, |
|
50 | - ), |
|
51 | - ), |
|
52 | - ) |
|
53 | - ); |
|
54 | - } |
|
34 | + register_rest_route( |
|
35 | + WL_REST_ROUTE_DEFAULT_NAMESPACE, |
|
36 | + "/{$this->rest_url_name}/template/", |
|
37 | + array( |
|
38 | + 'methods' => \WP_REST_Server::CREATABLE, |
|
39 | + 'callback' => array( $this, 'get_template' ), |
|
40 | + /** |
|
41 | + * We want this endpoint to be publicly accessible |
|
42 | + */ |
|
43 | + 'permission_callback' => '__return_true', |
|
44 | + 'args' => array( |
|
45 | + 'template_id' => array( |
|
46 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
47 | + 'validate_callback' => function ( $param, $request, $key ) { |
|
48 | + return is_string( $param ) && $param; |
|
49 | + }, |
|
50 | + ), |
|
51 | + ), |
|
52 | + ) |
|
53 | + ); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Shortcode widget makes call to this endpoint to get the template. |
|
58 | - * Takes the request, checks if template id is registered via filter, |
|
59 | - * if not it returns empty. |
|
60 | - * |
|
61 | - * @param $request \WP_REST_Request |
|
62 | - * |
|
63 | - * @return string Returns the template string. |
|
64 | - */ |
|
65 | - public function get_template( $request ) { |
|
66 | - $data = $request->get_params(); |
|
67 | - $template_id = (string) $data['template_id']; |
|
68 | - $templates = apply_filters( "wordlift_{$this->filter_name}_templates", array() ); |
|
69 | - $template = array_key_exists( $template_id, $templates ) ? $templates[ $template_id ] : ''; |
|
56 | + /** |
|
57 | + * Shortcode widget makes call to this endpoint to get the template. |
|
58 | + * Takes the request, checks if template id is registered via filter, |
|
59 | + * if not it returns empty. |
|
60 | + * |
|
61 | + * @param $request \WP_REST_Request |
|
62 | + * |
|
63 | + * @return string Returns the template string. |
|
64 | + */ |
|
65 | + public function get_template( $request ) { |
|
66 | + $data = $request->get_params(); |
|
67 | + $template_id = (string) $data['template_id']; |
|
68 | + $templates = apply_filters( "wordlift_{$this->filter_name}_templates", array() ); |
|
69 | + $template = array_key_exists( $template_id, $templates ) ? $templates[ $template_id ] : ''; |
|
70 | 70 | |
71 | - return array( 'template' => $template ); |
|
72 | - } |
|
71 | + return array( 'template' => $template ); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @param $shortcode_instance \Wordlift_Shortcode |
|
76 | - * |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - private static function get_widget_name( $shortcode_instance ) { |
|
80 | - $name = str_replace( 'wl_', '', $shortcode_instance::SHORTCODE ); |
|
74 | + /** |
|
75 | + * @param $shortcode_instance \Wordlift_Shortcode |
|
76 | + * |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + private static function get_widget_name( $shortcode_instance ) { |
|
80 | + $name = str_replace( 'wl_', '', $shortcode_instance::SHORTCODE ); |
|
81 | 81 | |
82 | - return str_replace( '_', '-', $name ); |
|
83 | - } |
|
82 | + return str_replace( '_', '-', $name ); |
|
83 | + } |
|
84 | 84 | |
85 | 85 | } |
@@ -23,10 +23,10 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param $shortcode_instance \Wordlift_Shortcode |
25 | 25 | */ |
26 | - public function __construct( $shortcode_instance ) { |
|
27 | - $this->rest_url_name = $this->get_widget_name( $shortcode_instance ); |
|
28 | - $this->filter_name = str_replace( '-', '_', $this->rest_url_name ); |
|
29 | - add_action( 'rest_api_init', array( $this, 'register_template_route' ) ); |
|
26 | + public function __construct($shortcode_instance) { |
|
27 | + $this->rest_url_name = $this->get_widget_name($shortcode_instance); |
|
28 | + $this->filter_name = str_replace('-', '_', $this->rest_url_name); |
|
29 | + add_action('rest_api_init', array($this, 'register_template_route')); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | public function register_template_route() { |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | "/{$this->rest_url_name}/template/", |
37 | 37 | array( |
38 | 38 | 'methods' => \WP_REST_Server::CREATABLE, |
39 | - 'callback' => array( $this, 'get_template' ), |
|
39 | + 'callback' => array($this, 'get_template'), |
|
40 | 40 | /** |
41 | 41 | * We want this endpoint to be publicly accessible |
42 | 42 | */ |
@@ -44,8 +44,8 @@ discard block |
||
44 | 44 | 'args' => array( |
45 | 45 | 'template_id' => array( |
46 | 46 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
47 | - 'validate_callback' => function ( $param, $request, $key ) { |
|
48 | - return is_string( $param ) && $param; |
|
47 | + 'validate_callback' => function($param, $request, $key) { |
|
48 | + return is_string($param) && $param; |
|
49 | 49 | }, |
50 | 50 | ), |
51 | 51 | ), |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | * |
63 | 63 | * @return string Returns the template string. |
64 | 64 | */ |
65 | - public function get_template( $request ) { |
|
65 | + public function get_template($request) { |
|
66 | 66 | $data = $request->get_params(); |
67 | 67 | $template_id = (string) $data['template_id']; |
68 | - $templates = apply_filters( "wordlift_{$this->filter_name}_templates", array() ); |
|
69 | - $template = array_key_exists( $template_id, $templates ) ? $templates[ $template_id ] : ''; |
|
68 | + $templates = apply_filters("wordlift_{$this->filter_name}_templates", array()); |
|
69 | + $template = array_key_exists($template_id, $templates) ? $templates[$template_id] : ''; |
|
70 | 70 | |
71 | - return array( 'template' => $template ); |
|
71 | + return array('template' => $template); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -76,10 +76,10 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @return string |
78 | 78 | */ |
79 | - private static function get_widget_name( $shortcode_instance ) { |
|
80 | - $name = str_replace( 'wl_', '', $shortcode_instance::SHORTCODE ); |
|
79 | + private static function get_widget_name($shortcode_instance) { |
|
80 | + $name = str_replace('wl_', '', $shortcode_instance::SHORTCODE); |
|
81 | 81 | |
82 | - return str_replace( '_', '-', $name ); |
|
82 | + return str_replace('_', '-', $name); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | } |
@@ -8,53 +8,53 @@ |
||
8 | 8 | */ |
9 | 9 | class Srcset_Util { |
10 | 10 | |
11 | - const NAVIGATOR_WIDGET = 'navigator'; |
|
12 | - |
|
13 | - const FACETED_SEARCH_WIDGET = 'faceted_search'; |
|
14 | - |
|
15 | - public static function get_srcset( $post_id, $widget_name ) { |
|
16 | - |
|
17 | - $srcset = array(); |
|
18 | - $medium = get_the_post_thumbnail_url( $post_id, 'medium' ); |
|
19 | - $large = get_the_post_thumbnail_url( $post_id, 'large' ); |
|
20 | - |
|
21 | - $width = self::get_image_width( $post_id, 'medium' ); |
|
22 | - if ( $medium && $width ) { |
|
23 | - $srcset[] = $medium . ' ' . $width . 'w'; |
|
24 | - } |
|
25 | - |
|
26 | - $width = self::get_image_width( $post_id, 'large' ); |
|
27 | - if ( $large && $width ) { |
|
28 | - $srcset[] = $large . ' ' . $width . 'w'; |
|
29 | - } |
|
30 | - |
|
31 | - $srcset_string = join( ',', $srcset ); |
|
32 | - |
|
33 | - /** |
|
34 | - * Filter name: wordlift_${widget_name}_thumbnail_srcset |
|
35 | - * Filters the srcset string supplied to widgets for each post. |
|
36 | - * |
|
37 | - * @param $srcset_string string The srcset string |
|
38 | - * |
|
39 | - * @since 3.28.0 |
|
40 | - */ |
|
41 | - $srcset_string = apply_filters( "wordlift_${widget_name}_thumbnail_srcset", $srcset_string ); |
|
42 | - |
|
43 | - return $srcset_string; |
|
44 | - |
|
45 | - } |
|
46 | - |
|
47 | - private static function get_image_width( $post_id, $size ) { |
|
48 | - $thumbnail_id = get_post_thumbnail_id( $post_id ); |
|
49 | - if ( ! $thumbnail_id ) { |
|
50 | - return false; |
|
51 | - } |
|
52 | - $data = wp_get_attachment_image_src( $thumbnail_id, $size ); |
|
53 | - if ( ! $data ) { |
|
54 | - return false; |
|
55 | - } |
|
56 | - |
|
57 | - return array_key_exists( 2, $data ) ? $data[2] : false; |
|
58 | - } |
|
11 | + const NAVIGATOR_WIDGET = 'navigator'; |
|
12 | + |
|
13 | + const FACETED_SEARCH_WIDGET = 'faceted_search'; |
|
14 | + |
|
15 | + public static function get_srcset( $post_id, $widget_name ) { |
|
16 | + |
|
17 | + $srcset = array(); |
|
18 | + $medium = get_the_post_thumbnail_url( $post_id, 'medium' ); |
|
19 | + $large = get_the_post_thumbnail_url( $post_id, 'large' ); |
|
20 | + |
|
21 | + $width = self::get_image_width( $post_id, 'medium' ); |
|
22 | + if ( $medium && $width ) { |
|
23 | + $srcset[] = $medium . ' ' . $width . 'w'; |
|
24 | + } |
|
25 | + |
|
26 | + $width = self::get_image_width( $post_id, 'large' ); |
|
27 | + if ( $large && $width ) { |
|
28 | + $srcset[] = $large . ' ' . $width . 'w'; |
|
29 | + } |
|
30 | + |
|
31 | + $srcset_string = join( ',', $srcset ); |
|
32 | + |
|
33 | + /** |
|
34 | + * Filter name: wordlift_${widget_name}_thumbnail_srcset |
|
35 | + * Filters the srcset string supplied to widgets for each post. |
|
36 | + * |
|
37 | + * @param $srcset_string string The srcset string |
|
38 | + * |
|
39 | + * @since 3.28.0 |
|
40 | + */ |
|
41 | + $srcset_string = apply_filters( "wordlift_${widget_name}_thumbnail_srcset", $srcset_string ); |
|
42 | + |
|
43 | + return $srcset_string; |
|
44 | + |
|
45 | + } |
|
46 | + |
|
47 | + private static function get_image_width( $post_id, $size ) { |
|
48 | + $thumbnail_id = get_post_thumbnail_id( $post_id ); |
|
49 | + if ( ! $thumbnail_id ) { |
|
50 | + return false; |
|
51 | + } |
|
52 | + $data = wp_get_attachment_image_src( $thumbnail_id, $size ); |
|
53 | + if ( ! $data ) { |
|
54 | + return false; |
|
55 | + } |
|
56 | + |
|
57 | + return array_key_exists( 2, $data ) ? $data[2] : false; |
|
58 | + } |
|
59 | 59 | |
60 | 60 | } |
@@ -12,23 +12,23 @@ discard block |
||
12 | 12 | |
13 | 13 | const FACETED_SEARCH_WIDGET = 'faceted_search'; |
14 | 14 | |
15 | - public static function get_srcset( $post_id, $widget_name ) { |
|
15 | + public static function get_srcset($post_id, $widget_name) { |
|
16 | 16 | |
17 | 17 | $srcset = array(); |
18 | - $medium = get_the_post_thumbnail_url( $post_id, 'medium' ); |
|
19 | - $large = get_the_post_thumbnail_url( $post_id, 'large' ); |
|
18 | + $medium = get_the_post_thumbnail_url($post_id, 'medium'); |
|
19 | + $large = get_the_post_thumbnail_url($post_id, 'large'); |
|
20 | 20 | |
21 | - $width = self::get_image_width( $post_id, 'medium' ); |
|
22 | - if ( $medium && $width ) { |
|
23 | - $srcset[] = $medium . ' ' . $width . 'w'; |
|
21 | + $width = self::get_image_width($post_id, 'medium'); |
|
22 | + if ($medium && $width) { |
|
23 | + $srcset[] = $medium.' '.$width.'w'; |
|
24 | 24 | } |
25 | 25 | |
26 | - $width = self::get_image_width( $post_id, 'large' ); |
|
27 | - if ( $large && $width ) { |
|
28 | - $srcset[] = $large . ' ' . $width . 'w'; |
|
26 | + $width = self::get_image_width($post_id, 'large'); |
|
27 | + if ($large && $width) { |
|
28 | + $srcset[] = $large.' '.$width.'w'; |
|
29 | 29 | } |
30 | 30 | |
31 | - $srcset_string = join( ',', $srcset ); |
|
31 | + $srcset_string = join(',', $srcset); |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Filter name: wordlift_${widget_name}_thumbnail_srcset |
@@ -38,23 +38,23 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @since 3.28.0 |
40 | 40 | */ |
41 | - $srcset_string = apply_filters( "wordlift_${widget_name}_thumbnail_srcset", $srcset_string ); |
|
41 | + $srcset_string = apply_filters("wordlift_${widget_name}_thumbnail_srcset", $srcset_string); |
|
42 | 42 | |
43 | 43 | return $srcset_string; |
44 | 44 | |
45 | 45 | } |
46 | 46 | |
47 | - private static function get_image_width( $post_id, $size ) { |
|
48 | - $thumbnail_id = get_post_thumbnail_id( $post_id ); |
|
49 | - if ( ! $thumbnail_id ) { |
|
47 | + private static function get_image_width($post_id, $size) { |
|
48 | + $thumbnail_id = get_post_thumbnail_id($post_id); |
|
49 | + if ( ! $thumbnail_id) { |
|
50 | 50 | return false; |
51 | 51 | } |
52 | - $data = wp_get_attachment_image_src( $thumbnail_id, $size ); |
|
53 | - if ( ! $data ) { |
|
52 | + $data = wp_get_attachment_image_src($thumbnail_id, $size); |
|
53 | + if ( ! $data) { |
|
54 | 54 | return false; |
55 | 55 | } |
56 | 56 | |
57 | - return array_key_exists( 2, $data ) ? $data[2] : false; |
|
57 | + return array_key_exists(2, $data) ? $data[2] : false; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | } |
@@ -8,54 +8,54 @@ discard block |
||
8 | 8 | */ |
9 | 9 | class Navigator_Data { |
10 | 10 | |
11 | - public static function get_post_types_as_string( $post_types ) { |
|
12 | - if ( array() === $post_types ) { |
|
13 | - $post_types = get_post_types(); |
|
14 | - } |
|
15 | - $post_types = array_map( |
|
16 | - function ( $post_type ) { |
|
17 | - return "'" . esc_sql( $post_type ) . "'"; |
|
18 | - }, |
|
19 | - $post_types |
|
20 | - ); |
|
11 | + public static function get_post_types_as_string( $post_types ) { |
|
12 | + if ( array() === $post_types ) { |
|
13 | + $post_types = get_post_types(); |
|
14 | + } |
|
15 | + $post_types = array_map( |
|
16 | + function ( $post_type ) { |
|
17 | + return "'" . esc_sql( $post_type ) . "'"; |
|
18 | + }, |
|
19 | + $post_types |
|
20 | + ); |
|
21 | 21 | |
22 | - return implode( ',', $post_types ); |
|
23 | - } |
|
22 | + return implode( ',', $post_types ); |
|
23 | + } |
|
24 | 24 | |
25 | - public static function post_navigator_get_results( |
|
26 | - $post_id, $fields = array( |
|
27 | - 'ID', |
|
28 | - 'post_title', |
|
29 | - ), $order_by = 'ID DESC', $limit = 10, $offset = 0, $post_types = array() |
|
30 | - ) { |
|
25 | + public static function post_navigator_get_results( |
|
26 | + $post_id, $fields = array( |
|
27 | + 'ID', |
|
28 | + 'post_title', |
|
29 | + ), $order_by = 'ID DESC', $limit = 10, $offset = 0, $post_types = array() |
|
30 | + ) { |
|
31 | 31 | |
32 | - $post_types = self::get_post_types_as_string( $post_types ); |
|
33 | - global $wpdb; |
|
32 | + $post_types = self::get_post_types_as_string( $post_types ); |
|
33 | + global $wpdb; |
|
34 | 34 | |
35 | - $select = implode( |
|
36 | - ', ', |
|
37 | - array_map( |
|
38 | - function ( $item ) { |
|
39 | - return "p.$item AS $item"; |
|
40 | - }, |
|
41 | - (array) $fields |
|
42 | - ) |
|
43 | - ); |
|
35 | + $select = implode( |
|
36 | + ', ', |
|
37 | + array_map( |
|
38 | + function ( $item ) { |
|
39 | + return "p.$item AS $item"; |
|
40 | + }, |
|
41 | + (array) $fields |
|
42 | + ) |
|
43 | + ); |
|
44 | 44 | |
45 | - $order_by = implode( |
|
46 | - ', ', |
|
47 | - array_map( |
|
48 | - function ( $item ) { |
|
49 | - return "p.$item"; |
|
50 | - }, |
|
51 | - (array) $order_by |
|
52 | - ) |
|
53 | - ); |
|
45 | + $order_by = implode( |
|
46 | + ', ', |
|
47 | + array_map( |
|
48 | + function ( $item ) { |
|
49 | + return "p.$item"; |
|
50 | + }, |
|
51 | + (array) $order_by |
|
52 | + ) |
|
53 | + ); |
|
54 | 54 | // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder |
55 | - /** @noinspection SqlNoDataSourceInspection */ |
|
56 | - return $wpdb->get_results( |
|
57 | - $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber |
|
58 | - " |
|
55 | + /** @noinspection SqlNoDataSourceInspection */ |
|
56 | + return $wpdb->get_results( |
|
57 | + $wpdb->prepare( // phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber |
|
58 | + " |
|
59 | 59 | SELECT %4\$s, p2.ID as entity_id |
60 | 60 | FROM {$wpdb->prefix}wl_relation_instances r1 |
61 | 61 | INNER JOIN {$wpdb->prefix}wl_relation_instances r2 |
@@ -89,50 +89,50 @@ discard block |
||
89 | 89 | LIMIT %2\$d |
90 | 90 | OFFSET %3\$d |
91 | 91 | ", |
92 | - $post_id, |
|
93 | - $limit, |
|
94 | - $offset, |
|
95 | - $select, |
|
96 | - $order_by |
|
97 | - ) |
|
98 | - ); |
|
92 | + $post_id, |
|
93 | + $limit, |
|
94 | + $offset, |
|
95 | + $select, |
|
96 | + $order_by |
|
97 | + ) |
|
98 | + ); |
|
99 | 99 | // phpcs:enable |
100 | - } |
|
100 | + } |
|
101 | 101 | |
102 | - public static function entity_navigator_get_results( |
|
103 | - $post_id, $fields = array( |
|
104 | - 'ID', |
|
105 | - 'post_title', |
|
106 | - ), $order_by = 'ID DESC', $limit = 10, $offset = 0, $post_types = array() |
|
107 | - ) { |
|
108 | - global $wpdb; |
|
102 | + public static function entity_navigator_get_results( |
|
103 | + $post_id, $fields = array( |
|
104 | + 'ID', |
|
105 | + 'post_title', |
|
106 | + ), $order_by = 'ID DESC', $limit = 10, $offset = 0, $post_types = array() |
|
107 | + ) { |
|
108 | + global $wpdb; |
|
109 | 109 | |
110 | - $select = implode( |
|
111 | - ', ', |
|
112 | - array_map( |
|
113 | - function ( $item ) { |
|
114 | - return "p.$item AS $item"; |
|
115 | - }, |
|
116 | - (array) $fields |
|
117 | - ) |
|
118 | - ); |
|
110 | + $select = implode( |
|
111 | + ', ', |
|
112 | + array_map( |
|
113 | + function ( $item ) { |
|
114 | + return "p.$item AS $item"; |
|
115 | + }, |
|
116 | + (array) $fields |
|
117 | + ) |
|
118 | + ); |
|
119 | 119 | |
120 | - $order_by = implode( |
|
121 | - ', ', |
|
122 | - array_map( |
|
123 | - function ( $item ) { |
|
124 | - return "p.$item"; |
|
125 | - }, |
|
126 | - (array) $order_by |
|
127 | - ) |
|
128 | - ); |
|
120 | + $order_by = implode( |
|
121 | + ', ', |
|
122 | + array_map( |
|
123 | + function ( $item ) { |
|
124 | + return "p.$item"; |
|
125 | + }, |
|
126 | + (array) $order_by |
|
127 | + ) |
|
128 | + ); |
|
129 | 129 | |
130 | - $post_types = self::get_post_types_as_string( $post_types ); |
|
130 | + $post_types = self::get_post_types_as_string( $post_types ); |
|
131 | 131 | // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder |
132 | - /** @noinspection SqlNoDataSourceInspection */ |
|
133 | - return $wpdb->get_results( |
|
134 | - $wpdb->prepare( |
|
135 | - " |
|
132 | + /** @noinspection SqlNoDataSourceInspection */ |
|
133 | + return $wpdb->get_results( |
|
134 | + $wpdb->prepare( |
|
135 | + " |
|
136 | 136 | SELECT %4\$s, p2.ID as entity_id |
137 | 137 | FROM {$wpdb->prefix}wl_relation_instances r1 |
138 | 138 | -- get the ID of the post entity in common between the object and the subject 2. |
@@ -163,14 +163,14 @@ discard block |
||
163 | 163 | LIMIT %2\$d |
164 | 164 | OFFSET %3\$d |
165 | 165 | ", |
166 | - $post_id, |
|
167 | - $limit, |
|
168 | - $offset, |
|
169 | - $select, |
|
170 | - $order_by |
|
171 | - ) |
|
172 | - ); |
|
173 | - } |
|
166 | + $post_id, |
|
167 | + $limit, |
|
168 | + $offset, |
|
169 | + $select, |
|
170 | + $order_by |
|
171 | + ) |
|
172 | + ); |
|
173 | + } |
|
174 | 174 | // phpcs:enable |
175 | 175 | } |
176 | 176 |
@@ -8,18 +8,18 @@ discard block |
||
8 | 8 | */ |
9 | 9 | class Navigator_Data { |
10 | 10 | |
11 | - public static function get_post_types_as_string( $post_types ) { |
|
12 | - if ( array() === $post_types ) { |
|
11 | + public static function get_post_types_as_string($post_types) { |
|
12 | + if (array() === $post_types) { |
|
13 | 13 | $post_types = get_post_types(); |
14 | 14 | } |
15 | 15 | $post_types = array_map( |
16 | - function ( $post_type ) { |
|
17 | - return "'" . esc_sql( $post_type ) . "'"; |
|
16 | + function($post_type) { |
|
17 | + return "'".esc_sql($post_type)."'"; |
|
18 | 18 | }, |
19 | 19 | $post_types |
20 | 20 | ); |
21 | 21 | |
22 | - return implode( ',', $post_types ); |
|
22 | + return implode(',', $post_types); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | public static function post_navigator_get_results( |
@@ -29,13 +29,13 @@ discard block |
||
29 | 29 | ), $order_by = 'ID DESC', $limit = 10, $offset = 0, $post_types = array() |
30 | 30 | ) { |
31 | 31 | |
32 | - $post_types = self::get_post_types_as_string( $post_types ); |
|
32 | + $post_types = self::get_post_types_as_string($post_types); |
|
33 | 33 | global $wpdb; |
34 | 34 | |
35 | 35 | $select = implode( |
36 | 36 | ', ', |
37 | 37 | array_map( |
38 | - function ( $item ) { |
|
38 | + function($item) { |
|
39 | 39 | return "p.$item AS $item"; |
40 | 40 | }, |
41 | 41 | (array) $fields |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | $order_by = implode( |
46 | 46 | ', ', |
47 | 47 | array_map( |
48 | - function ( $item ) { |
|
48 | + function($item) { |
|
49 | 49 | return "p.$item"; |
50 | 50 | }, |
51 | 51 | (array) $order_by |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $select = implode( |
111 | 111 | ', ', |
112 | 112 | array_map( |
113 | - function ( $item ) { |
|
113 | + function($item) { |
|
114 | 114 | return "p.$item AS $item"; |
115 | 115 | }, |
116 | 116 | (array) $fields |
@@ -120,14 +120,14 @@ discard block |
||
120 | 120 | $order_by = implode( |
121 | 121 | ', ', |
122 | 122 | array_map( |
123 | - function ( $item ) { |
|
123 | + function($item) { |
|
124 | 124 | return "p.$item"; |
125 | 125 | }, |
126 | 126 | (array) $order_by |
127 | 127 | ) |
128 | 128 | ); |
129 | 129 | |
130 | - $post_types = self::get_post_types_as_string( $post_types ); |
|
130 | + $post_types = self::get_post_types_as_string($post_types); |
|
131 | 131 | // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder |
132 | 132 | /** @noinspection SqlNoDataSourceInspection */ |
133 | 133 | return $wpdb->get_results( |
@@ -16,17 +16,17 @@ |
||
16 | 16 | */ |
17 | 17 | class Same_Category_Filler_Posts extends Filler_Posts { |
18 | 18 | |
19 | - public function get_posts( $filler_count, $post_ids_to_be_excluded ) { |
|
19 | + public function get_posts( $filler_count, $post_ids_to_be_excluded ) { |
|
20 | 20 | |
21 | - $current_post_categories = wp_get_post_categories( $this->post_id ); |
|
22 | - $post_type = $this->alternate_post_type ? $this->alternate_post_type : get_post_types(); |
|
21 | + $current_post_categories = wp_get_post_categories( $this->post_id ); |
|
22 | + $post_type = $this->alternate_post_type ? $this->alternate_post_type : get_post_types(); |
|
23 | 23 | |
24 | - return get_posts( |
|
25 | - array( |
|
26 | - 'category__in' => $current_post_categories, |
|
27 | - 'post_type' => $post_type, |
|
28 | - ) |
|
29 | - + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded ) |
|
30 | - ); |
|
31 | - } |
|
24 | + return get_posts( |
|
25 | + array( |
|
26 | + 'category__in' => $current_post_categories, |
|
27 | + 'post_type' => $post_type, |
|
28 | + ) |
|
29 | + + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded ) |
|
30 | + ); |
|
31 | + } |
|
32 | 32 | } |
@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class Same_Category_Filler_Posts extends Filler_Posts { |
18 | 18 | |
19 | - public function get_posts( $filler_count, $post_ids_to_be_excluded ) { |
|
19 | + public function get_posts($filler_count, $post_ids_to_be_excluded) { |
|
20 | 20 | |
21 | - $current_post_categories = wp_get_post_categories( $this->post_id ); |
|
21 | + $current_post_categories = wp_get_post_categories($this->post_id); |
|
22 | 22 | $post_type = $this->alternate_post_type ? $this->alternate_post_type : get_post_types(); |
23 | 23 | |
24 | 24 | return get_posts( |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | 'category__in' => $current_post_categories, |
27 | 27 | 'post_type' => $post_type, |
28 | 28 | ) |
29 | - + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded ) |
|
29 | + + $this->get_posts_config($filler_count, $post_ids_to_be_excluded) |
|
30 | 30 | ); |
31 | 31 | } |
32 | 32 | } |
@@ -8,16 +8,16 @@ |
||
8 | 8 | */ |
9 | 9 | class Same_Post_Type_Same_Category_Posts extends Filler_Posts { |
10 | 10 | |
11 | - public function get_posts( $filler_count, $post_ids_to_be_excluded ) { |
|
12 | - $current_post_categories = wp_get_post_categories( $this->post_id ); |
|
13 | - $post_type = $this->alternate_post_type ? $this->alternate_post_type : get_post_type( $this->post_id ); |
|
11 | + public function get_posts( $filler_count, $post_ids_to_be_excluded ) { |
|
12 | + $current_post_categories = wp_get_post_categories( $this->post_id ); |
|
13 | + $post_type = $this->alternate_post_type ? $this->alternate_post_type : get_post_type( $this->post_id ); |
|
14 | 14 | |
15 | - return get_posts( |
|
16 | - array( |
|
17 | - 'category__in' => $current_post_categories, |
|
18 | - 'post_type' => $post_type, |
|
19 | - ) |
|
20 | - + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded ) |
|
21 | - ); |
|
22 | - } |
|
15 | + return get_posts( |
|
16 | + array( |
|
17 | + 'category__in' => $current_post_categories, |
|
18 | + 'post_type' => $post_type, |
|
19 | + ) |
|
20 | + + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded ) |
|
21 | + ); |
|
22 | + } |
|
23 | 23 | } |
@@ -8,16 +8,16 @@ |
||
8 | 8 | */ |
9 | 9 | class Same_Post_Type_Same_Category_Posts extends Filler_Posts { |
10 | 10 | |
11 | - public function get_posts( $filler_count, $post_ids_to_be_excluded ) { |
|
12 | - $current_post_categories = wp_get_post_categories( $this->post_id ); |
|
13 | - $post_type = $this->alternate_post_type ? $this->alternate_post_type : get_post_type( $this->post_id ); |
|
11 | + public function get_posts($filler_count, $post_ids_to_be_excluded) { |
|
12 | + $current_post_categories = wp_get_post_categories($this->post_id); |
|
13 | + $post_type = $this->alternate_post_type ? $this->alternate_post_type : get_post_type($this->post_id); |
|
14 | 14 | |
15 | 15 | return get_posts( |
16 | 16 | array( |
17 | 17 | 'category__in' => $current_post_categories, |
18 | 18 | 'post_type' => $post_type, |
19 | 19 | ) |
20 | - + $this->get_posts_config( $filler_count, $post_ids_to_be_excluded ) |
|
20 | + + $this->get_posts_config($filler_count, $post_ids_to_be_excluded) |
|
21 | 21 | ); |
22 | 22 | } |
23 | 23 | } |