51 public $buttonPrimary;
115 public function __construct( $id, $selector, $title, $content, $edge =
'left', $align =
'top' ) {
116 $this->
id = sanitize_key( $id );
117 $this->selector = $selector;
118 $this->title = $title;
119 $this->content = $content;
121 $this->align = $align;
123 $this->nextPage =
'';
125 $this->buttonClose = array(
126 'id' =>
'wpdk-pointer-button-close',
127 'label' => __(
'Dismiss', WPDK_TEXTDOMAIN ),
133 $this->buttonPrimary = array(
134 'id' =>
'wpdk-button-pointer-next',
135 'label' => __(
'Next', WPDK_TEXTDOMAIN ),
139 add_action(
'admin_print_footer_scripts', array( $this,
'display' ) );
148 public function display() {
151 $pointer_id = $this->id;
152 $selector = $this->selector;
156 'content' => sprintf(
'%s%s', $this->_title(), $this->_content() ),
158 'edge' => $this->edge,
159 'align' => $this->align
164 if ( empty( $pointer_id ) || empty( $selector ) || empty( $args ) || empty( $args[
'content'] ) ) {
169 $id_user = get_current_user_id();
172 $dismissed = unserialize( get_user_meta( $id_user,
'wpdk_dismissed_wp_pointer',
true ) );
173 if ( isset( $dismissed[$pointer_id] ) ) {
178 if ( !empty( $this->nextPage ) ) {
179 $this->buttonPrimary[
'page'] = $this->nextPage;
183 <script type=
"text/javascript">
185 jQuery( document ).ready(
function ( $ ) {
186 var options = <?php echo json_encode( $args ); ?>, setup;
192 options = $.extend( options, {
194 buttons :
function ( event, t ) {
195 var button = jQuery(
'<?php echo $this->_buttonClose() ?>' );
196 button.bind(
'click.pointer',
function () {
197 t.element.pointer(
'close' );
202 close :
function () {
203 var button = jQuery(
'#<?php echo $this->buttonClose['id'] ?>' );
204 <?php
if ( empty( $this->buttonClose[
'function'] ) ) : ?>
205 if( button.data(
'dismiss') ) {
207 pointer :
'<?php echo $pointer_id; ?>',
208 action :
'wpdk_action_dismiss_wp_pointer'
212 <?php echo $this->buttonClose[
'function'] ?>
217 $(
'<?php echo $selector; ?>' ).pointer( options ).pointer(
'open' );
219 <?php
if ( !empty( $this->buttonPrimary ) && !empty( $this->buttonPrimary[
'page']) ) : ?>
220 $(
'#<?php echo $this->buttonClose['id'] ?>' ).after(
'<?php echo $this->_buttonPrimary() ?>' );
221 $(
'#<?php echo $this->buttonPrimary['id'] ?>' ).click(
function () {
223 if ( empty( $this->buttonPrimary[
'function'] ) && !empty( $this->buttonPrimary[
'page'] ) ) {
224 echo
'window.location="' . admin_url(
'admin.php?page=' . $this->buttonPrimary[
'page'] ) .
'";';
226 elseif ( !empty( $this->buttonPrimary[
'function'] ) ) {
227 echo $this->buttonPrimary[
'function'];
246 private function _title() {
247 if (
'<' != substr( $this->title, 0, 1 ) ) {
248 return sprintf(
'<h3>%s</h3>', $this->title );
260 private function _content() {
261 if (
'<' != substr( $this->content, 0, 1 ) ) {
262 return sprintf(
'<p>%s</p>', $this->content );
264 return $this->content;
274 private function _buttonClose() {
276 if( isset( $this->buttonClose[
'dismiss']) &&
true === $this->buttonClose[
'dismiss'] ) {
277 $dismiss =
'data-dismiss="true"';
279 $result = sprintf(
'<a id="%s" %s class="button-secondary">%s</a>', $this->buttonClose[
'id'], $dismiss, $this->buttonClose[
'label'] );
290 private function _buttonPrimary() {
291 $result = sprintf(
'<a id="%s" style="margin-right:5px" class="button-primary">%s</a>', $this->buttonPrimary[
'id'], $this->buttonPrimary[
'label'] );
307 class WPDKPointerButton {