-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathls-wp-ccsearch-pointer.php
95 lines (75 loc) · 2.88 KB
/
ls-wp-ccsearch-pointer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
*
*/
//Code from on https://code.tutsplus.com/articles/integrating-with-wordpress-ui-admin-pointers--wp-26853
add_action( 'admin_enqueue_scripts', 'wp_ccsearch_pointer_load', 1000 );
/**
*
* @param type $hook_suffix
* @return type
* @since v.0.4.0
*/
function wp_ccsearch_pointer_load( $hook_suffix ) {
$screen = get_current_screen();
$screen_id = $screen->id;
// Get pointers for this screen
$pointers = apply_filters( 'wp_ccsearch_admin_pointers-' . $screen_id, array() );
if ( ! $pointers || ! is_array( $pointers ) )
return;
// Get dismissed pointers
$dismissed = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
$valid_pointers =array();
// Check pointers and remove dismissed ones.
foreach ( $pointers as $pointer_id => $pointer ) {
// Sanity check
if ( in_array( $pointer_id, $dismissed ) || empty( $pointer ) || empty( $pointer_id ) || empty( $pointer['target'] ) || empty( $pointer['options'] ) )
continue;
$pointer['pointer_id'] = $pointer_id;
// Add the pointer to $valid_pointers array
$valid_pointers['pointers'][] = $pointer;
}
// No valid pointers? Stop here.
if ( empty( $valid_pointers ) ) {
return;
}
// Add pointers style to queue.
wp_enqueue_style( 'wp-pointer' );
// Add pointers script to queue. Add custom script.
wp_enqueue_script( 'wp_ccsearch-pointer', plugins_url( 'assets/js/wppointer.js', __FILE__ ), array( 'wp-pointer' ) );
// Add pointer options to script.
wp_localize_script( 'wp_ccsearch-pointer', 'wp_ccsearch_Pointer', $valid_pointers );
}
add_filter( 'wp_ccsearch_admin_pointers-post', 'wp_ccsearch_register_pointer' );
add_filter( 'wp_ccsearch_admin_pointers-page', 'wp_ccsearch_register_pointer' );
/**
*
* @param array $p
* @return array
* @since v.0.4.0
*/
function wp_ccsearch_register_pointer( $p ) {
$p['cs90190'] = array(
'pointer_id'=>'lswpcc_pointer',
'target' => '#lswpcc_btn',
'options' => array(
'content' => sprintf( '<h3> %s </h3> <p> %s </p>',
__( 'Find an image' ,'ls-wp-ccsearch'),
__( 'Use it to search millions of free photos then insert an image into content or set as featured image very quickly.','ls-wp-ccsearch')
),
'position' => array( 'edge' => 'left', 'align' => 'left' )
)
);
return $p;
}
/**
* Registers the block using the metadata loaded from the `block.json` file.
* Behind the scenes, it registers also all assets so they can be enqueued
* through the block editor in the corresponding context.
*
* @see https://developer.wordpress.org/reference/functions/register_block_type/
*/
function wp_ccsearch_block_init() {
register_block_type(__DIR__ . '/blocks/build');
}
add_action('init', 'wp_ccsearch_block_init');