forked from linchpin/mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.mesh-pointers.php
133 lines (111 loc) · 3.7 KB
/
class.mesh-pointers.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
/**
* Handle everything related to Admin Pointers
*
* @package Mesh
* @subpackage Admin_Pointers
*/
/**
* Class Mesh Pointers
*/
class Mesh_Admin_Pointers {
/**
* Mesh_Admin_Pointers constructor.
*/
function __construct() {
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
// @todo this filter needs to support multiple post types
add_filter( 'mesh_admin_pointers-page', array( $this, 'register_pointers' ) );
// Output our pointer data.
add_filter( 'mesh_data', array( $this, 'add_pointers' ), 1000, 1 );
}
/**
* Add our pointer styles
*/
function admin_enqueue_scripts() {
// Add pointers style to queue.
wp_enqueue_style( 'wp-pointer' );
}
/**
* Add pointer data to mesh_data->strings
*
* @param array $strings Array of our l10n strings
*
* @return array
*/
function add_pointers( $localized_data = array() ) {
// Don't run on WP < 3.3.
if ( get_bloginfo( 'version' ) < '3.3' ) {
return $localized_data;
}
$screen = get_current_screen();
$screen_id = $screen->id;
// Get pointers for this screen.
$pointers = apply_filters( 'mesh_admin_pointers-' . $screen_id, array() );
if ( ! $pointers || ! is_array( $pointers ) ) {
return $localized_data;
}
// 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, true ) || 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 $localized_data;
}
$localized_data['wp_pointers'] = $valid_pointers;
return $localized_data;
}
/**
* Register our WP Pointers for display
* @param $p
*
* @return mixed
*/
function register_pointers( $p ) {
$p['all_section_options'] = array(
'target' => '.mesh-more-section-options:first',
'options' => array(
'content' => sprintf( '<h3> %s </h3> <p> %s </p>',
__( 'Section Options' ,'mesh' ),
__( 'View all section options by click the "More Options" toggle.','mesh' )
),
'position' => array( 'edge' => 'bottom', 'align' => 'left' ),
),
);
$p['offset'] = array(
'target' => '.mesh-column-offset:first',
'options' => array(
'content' => sprintf( '<h3> %s </h3> <p> %s </p>',
__( 'What is an offset?' ,'mesh' ),
__( 'If using Foundation, an offset will indent your column by the amount of columns selected in the dropdown menu.', 'mesh' )
),
'position' => array( 'edge' => 'bottom', 'align' => 'left' ),
),
);
$p['column_slider'] = array(
'target' => '.mesh-editor-blocks .the-mover:first',
'options' => array(
'content' => sprintf( '<h3> %s </h3> <p> %s </p>',
__( 'Rearrange Columns', 'mesh' ),
__( 'Use this handle to click and drag this column, giving you the ability to swap columns on the fly.', 'mesh' )
),
'position' => array(
'edge' => 'left',
'align' => 'top',
),
'pointerClass' => 'wp-pointer mesh-pointer-top-left',
),
);
return $p;
}
}