| 1 |
<?php |
| 2 |
/** |
| 3 |
* class-groups-help.php |
| 4 |
* |
| 5 |
* Copyright (c) "kento" Karim Rahimpur www.itthinx.com |
| 6 |
* |
| 7 |
* This code is released under the GNU General Public License. |
| 8 |
* See COPYRIGHT.txt and LICENSE.txt. |
| 9 |
* |
| 10 |
* This code is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* This header and all notices must be kept intact. |
| 16 |
* |
| 17 |
* @author Karim Rahimpur |
| 18 |
* @package groups |
| 19 |
* @since groups 1.0.0 |
| 20 |
*/ |
| 21 |
|
| 22 |
if ( !defined( 'ABSPATH' ) ) { |
| 23 |
exit; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Help renderer. |
| 28 |
*/ |
| 29 |
class Groups_Help { |
| 30 |
|
| 31 |
/** |
| 32 |
* Help setup. |
| 33 |
*/ |
| 34 |
public static function init() { |
| 35 |
add_action( 'groups_admin_menu', array( __CLASS__, 'groups_admin_menu' ) ); |
| 36 |
// @todo temporary fix for GFA <= 1.0.11 on localized installations - can be removed when all are updated |
| 37 |
if ( defined( 'GFA_VIEWS_LIB' ) ) { |
| 38 |
if ( file_exists( GFA_VIEWS_LIB . '/class-gfa-help.php' ) ) { |
| 39 |
include_once GFA_VIEWS_LIB . '/class-gfa-help.php'; |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
add_filter( 'admin_footer_text', array( __CLASS__, 'admin_footer_text' ) ); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Adds contextual help to Groups admin screens. |
| 48 |
* |
| 49 |
* @param array $pages admin pages |
| 50 |
*/ |
| 51 |
public static function groups_admin_menu( $pages ) { |
| 52 |
foreach ( $pages as $page ) { |
| 53 |
add_action( 'load-' . $page, array( __CLASS__, 'contextual_help' ) ); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Adds help to an admin screen. |
| 59 |
*/ |
| 60 |
public static function contextual_help() { |
| 61 |
if ( $screen = get_current_screen() ) { |
| 62 |
$show_groups_help = false; |
| 63 |
$help_title = _x( 'Groups', 'Help title', 'groups' ); |
| 64 |
$screen_id = $screen->base; |
| 65 |
// The prefix of the $screen_id is translated, use only the suffix |
| 66 |
// to identify a screen: |
| 67 |
$ids = array( |
| 68 |
'groups-admin' => _x( 'Groups', 'Help tab title and heading', 'groups' ), |
| 69 |
'groups-admin-groups' => _x( 'Groups', 'Help tab title and heading', 'groups' ), |
| 70 |
'groups-admin-options' => _x( 'Options', 'Help tab title and heading', 'groups' ), |
| 71 |
'groups-admin-capabilities' => _x( 'Capabilities', 'Help tab title and heading', 'groups' ), |
| 72 |
); |
| 73 |
foreach ( $ids as $id => $title ) { |
| 74 |
$i = strpos( $screen_id, $id ); |
| 75 |
if ( $i !== false ) { |
| 76 |
if ( $i + strlen( $id ) == strlen( $screen_id ) ) { |
| 77 |
$screen_id = $id; |
| 78 |
$show_groups_help = true; |
| 79 |
$help_title = $title; |
| 80 |
break; |
| 81 |
} |
| 82 |
} |
| 83 |
} |
| 84 |
if ( $show_groups_help ) { |
| 85 |
$help = '<h3><a href="https://www.itthinx.com/plugins/groups" target="_blank">'. $help_title .'</a></h3>'; |
| 86 |
$help .= '<p>'; |
| 87 |
$help .= sprintf( |
| 88 |
/* translators: documentation pages link */ |
| 89 |
__( 'The complete documentation is available on the %s pages for Groups.', 'groups' ), |
| 90 |
sprintf( |
| 91 |
'<a href="https://docs.itthinx.com/document/groups">%s</a>', |
| 92 |
__( 'Documentation', 'groups' ) |
| 93 |
) |
| 94 |
); |
| 95 |
$help .= '</p>'; |
| 96 |
switch ( $screen_id ) { |
| 97 |
case 'groups-admin' : |
| 98 |
case 'groups-admin-groups': |
| 99 |
$help .= '<p>' . __( 'Here you can <strong>add</strong>, <strong>edit</strong> and <strong>remove</strong> groups.', 'groups' ) . '</p>'; |
| 100 |
break; |
| 101 |
case 'groups-admin-options' : |
| 102 |
case 'groups-admin-capabilities' : |
| 103 |
break; |
| 104 |
} |
| 105 |
|
| 106 |
$screen->add_help_tab( |
| 107 |
array( |
| 108 |
'id' => $screen_id, |
| 109 |
'title' => $help_title, |
| 110 |
'content' => $help |
| 111 |
) |
| 112 |
); |
| 113 |
} |
| 114 |
} |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Provides the footer text for Groups on relevant screens. |
| 119 |
* |
| 120 |
* @param string $text |
| 121 |
* |
| 122 |
* @return mixed |
| 123 |
*/ |
| 124 |
public static function admin_footer_text( $text ) { |
| 125 |
if ( function_exists( 'get_current_screen' ) ) { |
| 126 |
$current_screen = get_current_screen(); |
| 127 |
if ( |
| 128 |
isset( $current_screen->id ) && |
| 129 |
( |
| 130 |
stripos( $current_screen->id, 'groups-' ) === 0 || |
| 131 |
stripos( $current_screen->id, 'groups_' ) === 0 || |
| 132 |
stripos( $current_screen->id, 'toplevel_page_groups' ) === 0 |
| 133 |
) |
| 134 |
) { |
| 135 |
$text = self::footer( false ); |
| 136 |
} |
| 137 |
} |
| 138 |
return $text; |
| 139 |
} |
| 140 |
|
| 141 |
/** |
| 142 |
* Returns or renders the footer. |
| 143 |
* |
| 144 |
* @param boolean $render |
| 145 |
* |
| 146 |
* @return string|null |
| 147 |
*/ |
| 148 |
public static function footer( $render = true ) { |
| 149 |
$footer = |
| 150 |
'<span class="groups-footer">' . |
| 151 |
sprintf( |
| 152 |
/* translators: 1: link 2: link */ |
| 153 |
__( 'Thank you for using %1$s by %2$s.', 'groups' ), |
| 154 |
'<a href="https://www.itthinx.com/plugins/groups" target="_blank">Groups</a>', |
| 155 |
'<a href="https://www.itthinx.com" target="_blank">itthinx</a>' |
| 156 |
) . |
| 157 |
' ' . |
| 158 |
sprintf( |
| 159 |
/* translators: link */ |
| 160 |
__( 'Please give it a <a href="%s">★★★★★</a> rating.', 'groups' ), |
| 161 |
esc_attr( 'https://wordpress.org/support/view/plugin-reviews/groups?filter=5#postform' ) |
| 162 |
) . |
| 163 |
'</span>'; |
| 164 |
$footer = apply_filters( 'groups_footer', $footer ); |
| 165 |
if ( $render ) { |
| 166 |
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 167 |
echo $footer; // @phpstan-ignore return.missing |
| 168 |
} else { |
| 169 |
return $footer; |
| 170 |
} |
| 171 |
} |
| 172 |
} |
| 173 |
Groups_Help::init(); |
| 174 |
|