challenge
1 year ago
css
1 day ago
img
1 year ago
js
1 month ago
menu
1 month ago
partials
1 week ago
rest-api
1 day ago
scss
1 year ago
settings
1 day ago
uninstall
1 year ago
wpchill
1 month ago
admin-notices.php
5 months ago
admin.php
1 month ago
class-strong-testimonials-addons.php
1 month ago
class-strong-testimonials-admin-category-list.php
1 year ago
class-strong-testimonials-admin-list.php
1 year ago
class-strong-testimonials-admin-scripts.php
1 month ago
class-strong-testimonials-admin.php
1 month ago
class-strong-testimonials-debug.php
5 months ago
class-strong-testimonials-exporter.php
1 year ago
class-strong-testimonials-help.php
1 year ago
class-strong-testimonials-helper.php
1 month ago
class-strong-testimonials-list-table.php
1 year ago
class-strong-testimonials-lite-vs-pro-page.php
1 month ago
class-strong-testimonials-post-editor.php
6 months ago
class-strong-testimonials-review.php
1 year ago
class-strong-testimonials-updater.php
1 month ago
class-strong-testimonials-upsell.php
1 day ago
class-strong-views-list-table.php
1 month ago
class-walker-strong-category-checklist.php
1 year ago
class-walker-strong-form-category-checklist.php
1 year ago
class-wpmtst-onboarding.php
1 year ago
compat.php
1 year ago
custom-fields-ajax.php
1 year ago
custom-fields.php
1 day ago
form-preview.php
1 year ago
view-list-order.php
1 year ago
views-ajax.php
1 month ago
views-validate.php
1 year ago
views.php
1 month ago
class-strong-testimonials-admin.php
169 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | class Strong_Testimonials_Admin { |
| 5 | |
| 6 | /** |
| 7 | * Holds the class object. |
| 8 | * |
| 9 | * @since 3.0.3 |
| 10 | * |
| 11 | * @var object |
| 12 | */ |
| 13 | public static $instance; |
| 14 | |
| 15 | /** |
| 16 | * WPMTST_Admin_Helpers constructor. |
| 17 | * |
| 18 | * @since 3.0.3 |
| 19 | */ |
| 20 | public function __construct() { |
| 21 | add_action( 'admin_enqueue_scripts', array( $this, 'register_script' ) ); |
| 22 | add_action( 'in_admin_header', array( $this, 'page_header' ) ); |
| 23 | add_filter( 'views_edit-wpm-testimonial', array( $this, 'add_onboarding_view' ), 20, 1 ); |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Returns the singleton instance of the class. |
| 28 | * |
| 29 | * @return object The Strong_Testimonials_Admin object. |
| 30 | * |
| 31 | * @since 3.0.3 |
| 32 | */ |
| 33 | public static function get_instance() { |
| 34 | |
| 35 | if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Strong_Testimonials_Admin ) ) { |
| 36 | self::$instance = new Strong_Testimonials_Admin(); |
| 37 | } |
| 38 | |
| 39 | return self::$instance; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Display the ST Admin Page Header |
| 44 | * |
| 45 | * @param bool $extra_class |
| 46 | * |
| 47 | * @since 3.0.3 |
| 48 | */ |
| 49 | public static function page_header() { |
| 50 | $current_screen = get_current_screen(); |
| 51 | |
| 52 | $allowed_bases = array( 'wpm-testimonial_page_testimonial-settings', 'wpm-testimonial_page_strong-testimonials-extensions' ); |
| 53 | $show_header = in_array( $current_screen->base, $allowed_bases, true ); |
| 54 | |
| 55 | if ( ! apply_filters( 'wpmtst_page_header', $show_header, $current_screen ) ) { |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | wp_enqueue_script( 'wpmtst-header' ); |
| 60 | wp_enqueue_style( 'wpmtst-header' ); |
| 61 | |
| 62 | ?> |
| 63 | <div id="wpmtst-admin-header-root"></div> |
| 64 | <?php |
| 65 | } |
| 66 | |
| 67 | public static function render_admin_tabs() { |
| 68 | $screen = get_current_screen(); |
| 69 | |
| 70 | $screen_to_tab = array( |
| 71 | 'edit' => 'all-testimonials', |
| 72 | 'wpm-testimonial_page_testimonial-settings' => 'testimonial-settings', |
| 73 | 'wpm-testimonial_page_strong-testimonials-extensions' => 'strong-testimonials-extensions', |
| 74 | ); |
| 75 | $active_tab = isset( $screen_to_tab[ $screen->base ] ) ? $screen_to_tab[ $screen->base ] : ''; |
| 76 | |
| 77 | $tabs = apply_filters( |
| 78 | 'wpmtst_admin_tabs', |
| 79 | array( |
| 80 | 'all-testimonials' => array( |
| 81 | 'label' => esc_html__( 'All Testimonials', 'strong-testimonials' ), |
| 82 | 'url' => admin_url( 'edit.php?post_type=wpm-testimonial' ), |
| 83 | ), |
| 84 | 'strong-testimonials-extensions' => array( |
| 85 | 'label' => esc_html__( 'Extensions', 'strong-testimonials' ), |
| 86 | 'url' => admin_url( 'edit.php?post_type=wpm-testimonial&page=strong-testimonials-extensions' ), |
| 87 | ), |
| 88 | ) |
| 89 | ); |
| 90 | |
| 91 | echo '<div class="wpmtst-nav-wrapper"><div class="wpmtst-nav-tab-wrapper wp-clearfix">'; |
| 92 | foreach ( $tabs as $slug => $tab ) { |
| 93 | $active = $active_tab === $slug ? ' wpmtst-nav-tab-active' : ''; |
| 94 | printf( |
| 95 | '<a href="%s" class="wpmtst-nav-tab%s">%s</a>', |
| 96 | esc_url( $tab['url'] ), |
| 97 | esc_attr( $active ), |
| 98 | esc_html( $tab['label'] ) |
| 99 | ); |
| 100 | } |
| 101 | echo '</div></div>'; |
| 102 | } |
| 103 | |
| 104 | public function register_script() { |
| 105 | $plugin_version = get_option( 'wpmtst_plugin_version' ); |
| 106 | |
| 107 | /** |
| 108 | * Header |
| 109 | * |
| 110 | * @since 3.0 |
| 111 | */ |
| 112 | $header_asset_file = WPMTST_DIR . 'assets/dist/header/index.asset.php'; |
| 113 | $header_asset = file_exists( $header_asset_file ) |
| 114 | ? require $header_asset_file |
| 115 | : array( |
| 116 | 'version' => $plugin_version, |
| 117 | ); |
| 118 | |
| 119 | wp_register_script( |
| 120 | 'wpmtst-header', |
| 121 | WPMTST_ASSETS_JS . 'header/index.js', |
| 122 | $header_asset['dependencies'], |
| 123 | $header_asset['version'], |
| 124 | true |
| 125 | ); |
| 126 | |
| 127 | wp_register_style( |
| 128 | 'wpmtst-header', |
| 129 | WPMTST_ASSETS_JS . 'header/index.css', |
| 130 | array(), |
| 131 | $header_asset['version'] |
| 132 | ); |
| 133 | } |
| 134 | |
| 135 | public function add_onboarding_view( $views ) { |
| 136 | $current_screen = get_current_screen(); |
| 137 | |
| 138 | if ( 'wpm-testimonial' !== $current_screen->post_type || ! in_array( $current_screen->base, array( 'edit', 'wpm-testimonial_page_testimonial-settings', 'wpm-testimonial_page_strong-testimonials-extensions' ), true ) ) { |
| 139 | return $views; |
| 140 | } |
| 141 | |
| 142 | $query = new WP_Query( |
| 143 | array( |
| 144 | 'post_type' => 'wpm-testimonial', |
| 145 | 'post_status' => array( |
| 146 | 'publish', |
| 147 | 'future', |
| 148 | 'trash', |
| 149 | 'draft', |
| 150 | 'inherit', |
| 151 | 'pending', |
| 152 | ), |
| 153 | ) |
| 154 | ); |
| 155 | |
| 156 | self::render_admin_tabs(); |
| 157 | |
| 158 | if ( ! $query->have_posts() ) { |
| 159 | global $wp_list_table; |
| 160 | $wp_list_table = new WPMTST_Onboarding(); |
| 161 | |
| 162 | return array(); |
| 163 | } |
| 164 | |
| 165 | return $views; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | Strong_Testimonials_Admin::get_instance(); |