3rd-party
3 days ago
abstracts
3 months ago
admin
2 weeks ago
emails
2 weeks ago
forms
3 days ago
helper
3 months ago
promoted-jobs
3 days ago
ui
2 weeks ago
widgets
2 weeks ago
class-access-token.php
2 years ago
class-dev-tools.php
2 years ago
class-guest-session.php
2 years ago
class-guest-user.php
2 years ago
class-job-dashboard-shortcode.php
6 months ago
class-job-listing-stats.php
2 years ago
class-job-overlay.php
2 years ago
class-stats-dashboard.php
2 years ago
class-stats-script.php
3 months ago
class-stats.php
3 months ago
class-wp-job-manager-ajax.php
2 months ago
class-wp-job-manager-api.php
6 years ago
class-wp-job-manager-blocks.php
2 weeks ago
class-wp-job-manager-cache-helper.php
3 months ago
class-wp-job-manager-category-walker.php
6 years ago
class-wp-job-manager-com-api.php
2 years ago
class-wp-job-manager-data-cleaner.php
2 years ago
class-wp-job-manager-data-exporter.php
3 months ago
class-wp-job-manager-dependency-checker.php
2 years ago
class-wp-job-manager-email-notifications.php
2 years ago
class-wp-job-manager-forms.php
5 years ago
class-wp-job-manager-geocode.php
2 weeks ago
class-wp-job-manager-install.php
2 years ago
class-wp-job-manager-post-types.php
3 days ago
class-wp-job-manager-recaptcha.php
6 months ago
class-wp-job-manager-rest-api.php
2 months ago
class-wp-job-manager-shortcodes.php
2 weeks ago
class-wp-job-manager-usage-tracking-data.php
2 years ago
class-wp-job-manager-usage-tracking.php
2 years ago
class-wp-job-manager-widget.php
2 weeks ago
class-wp-job-manager.php
3 months ago
trait-singleton.php
2 years ago
class-job-overlay.php
223 lines
| 1 | <?php |
| 2 | /** |
| 3 | * File containing the class Job_Overlay. |
| 4 | * |
| 5 | * @package wp-job-manager |
| 6 | */ |
| 7 | |
| 8 | namespace WP_Job_Manager; |
| 9 | |
| 10 | use WP_Job_Manager\UI\Modal_Dialog; |
| 11 | use WP_Job_Manager\UI\Notice; |
| 12 | use WP_Job_Manager\UI\UI; |
| 13 | use WP_Job_Manager\UI\UI_Elements; |
| 14 | |
| 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | exit; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Job details overlay. |
| 21 | * |
| 22 | * @since 2.3.0 |
| 23 | */ |
| 24 | class Job_Overlay { |
| 25 | |
| 26 | use Singleton; |
| 27 | |
| 28 | /** |
| 29 | * Constructor. |
| 30 | */ |
| 31 | public function __construct() { |
| 32 | add_action( 'job_manager_ajax_job_dashboard_overlay', [ $this, 'ajax_job_overlay' ] ); |
| 33 | add_action( 'wp_ajax_job_dashboard_overlay', [ $this, 'ajax_job_overlay' ] ); |
| 34 | add_action( 'current_screen', [ $this, 'init_admin_dashboard_overlay' ], 10 ); |
| 35 | add_action( 'job_manager_job_overlay_footer', [ $this, 'output_footer_actions' ], 10 ); |
| 36 | |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Render the job dashboard overlay content for an AJAX request. |
| 41 | */ |
| 42 | public function ajax_job_overlay() { |
| 43 | |
| 44 | // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Nonce check. |
| 45 | if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( wp_unslash( $_REQUEST['_wpnonce'] ), 'job_dashboard_overlay' ) ) { |
| 46 | wp_send_json_error( |
| 47 | Notice::error( |
| 48 | [ |
| 49 | 'message' => __( 'Invalid request.', 'wp-job-manager' ), |
| 50 | 'classes' => [ 'type-dialog' ], |
| 51 | ] |
| 52 | ) |
| 53 | ); |
| 54 | |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | $job_id = isset( $_REQUEST['job_id'] ) ? absint( $_REQUEST['job_id'] ) : null; |
| 59 | |
| 60 | $job = $job_id ? get_post( $job_id ) : null; |
| 61 | |
| 62 | $shortcode = Job_Dashboard_Shortcode::instance(); |
| 63 | |
| 64 | if ( ! $shortcode->can_manage_job( $job ) ) { |
| 65 | wp_send_json_error( |
| 66 | Notice::error( |
| 67 | [ |
| 68 | 'message' => __( 'Invalid Job ID.', 'wp-job-manager' ), |
| 69 | 'classes' => [ 'type-dialog' ], |
| 70 | ] |
| 71 | ) |
| 72 | ); |
| 73 | |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | $content = $this->render_job_overlay( $job ); |
| 78 | |
| 79 | wp_send_json_success( $content ); |
| 80 | |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Output the modal element. |
| 85 | */ |
| 86 | public function output_modal_element() { |
| 87 | |
| 88 | wp_enqueue_style( 'wp-job-manager-job-dashboard' ); |
| 89 | wp_enqueue_script( 'wp-job-manager-job-dashboard' ); |
| 90 | |
| 91 | $overlay = new Modal_Dialog( |
| 92 | [ |
| 93 | 'id' => 'jmDashboardOverlay', |
| 94 | 'class' => 'jm-dashboard__overlay', |
| 95 | ] |
| 96 | ); |
| 97 | |
| 98 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in Modal_Dialog class. |
| 99 | echo $overlay->render( '' ); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Get the job overlay content. |
| 104 | * |
| 105 | * @param \WP_Post $job |
| 106 | * |
| 107 | * @return string |
| 108 | */ |
| 109 | private function render_job_overlay( $job ) { |
| 110 | |
| 111 | ob_start(); |
| 112 | |
| 113 | get_job_manager_template( |
| 114 | 'job-dashboard-overlay.php', |
| 115 | [ |
| 116 | 'job' => $job, |
| 117 | ] |
| 118 | ); |
| 119 | |
| 120 | $content = ob_get_clean(); |
| 121 | |
| 122 | return $content; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Load and output overlay dependencies on the job listings screen. |
| 127 | * |
| 128 | * @output Modal HTML. |
| 129 | * |
| 130 | * @return void |
| 131 | */ |
| 132 | public function init_admin_dashboard_overlay() { |
| 133 | |
| 134 | if ( ! Stats::is_enabled() ) { |
| 135 | return; |
| 136 | } |
| 137 | |
| 138 | $screen = get_current_screen(); |
| 139 | |
| 140 | if ( ! $screen || 'edit-job_listing' !== $screen->id ) { |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | $this->init_dashboard_overlay(); |
| 145 | add_action( 'admin_footer', [ $this, 'output_modal_element' ] ); |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * Load scripts and output HTML skeleton for the job dashboard overlay. |
| 150 | * |
| 151 | * @output Modal HTML. |
| 152 | * |
| 153 | * @return void |
| 154 | */ |
| 155 | public function init_dashboard_overlay() { |
| 156 | |
| 157 | UI::ensure_styles(); |
| 158 | \WP_Job_Manager::register_script( 'wp-job-manager-job-dashboard', 'js/job-dashboard.js', null, true ); |
| 159 | \WP_Job_Manager::register_style( 'wp-job-manager-job-dashboard', 'css/job-dashboard.css', [ 'wp-job-manager-ui' ] ); |
| 160 | |
| 161 | $endpoint = is_admin() |
| 162 | ? add_query_arg( [ 'action' => 'job_dashboard_overlay' ], admin_url( 'admin-ajax.php' ) ) |
| 163 | : \WP_Job_Manager_Ajax::get_endpoint( 'job_dashboard_overlay' ); |
| 164 | $endpoint = wp_nonce_url( $endpoint, 'job_dashboard_overlay' ); |
| 165 | |
| 166 | wp_localize_script( |
| 167 | 'wp-job-manager-job-dashboard', |
| 168 | 'job_manager_job_dashboard', |
| 169 | [ |
| 170 | 'i18nConfirmDelete' => esc_html__( 'Are you sure you want to delete this listing?', 'wp-job-manager' ), |
| 171 | 'overlayEndpoint' => $endpoint, |
| 172 | 'statsEnabled' => \WP_Job_Manager\Stats::is_enabled(), |
| 173 | ] |
| 174 | ); |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Output the job actions in the overlay footer. |
| 179 | * |
| 180 | * @param \WP_Post $job |
| 181 | */ |
| 182 | public function output_footer_actions( $job ) { |
| 183 | |
| 184 | if ( is_admin() ) { |
| 185 | return; |
| 186 | } |
| 187 | |
| 188 | $job_actions = Job_Dashboard_Shortcode::instance()->get_job_actions( $job ); |
| 189 | |
| 190 | $buttons = []; |
| 191 | $actions = []; |
| 192 | if ( ! empty( $job_actions ) ) { |
| 193 | $primary = Job_Dashboard_Shortcode::get_primary_action( $job, $job_actions ); |
| 194 | |
| 195 | if ( $primary ) { |
| 196 | $buttons[] = [ |
| 197 | 'label' => $primary['label'], |
| 198 | 'url' => $primary['url'], |
| 199 | 'class' => 'job-dashboard-action-' . esc_attr( $primary['name'] ), |
| 200 | 'primary' => false, |
| 201 | ]; |
| 202 | } |
| 203 | |
| 204 | foreach ( $job_actions as $action ) { |
| 205 | if ( ! empty( $primary ) && $primary['name'] === $action['name'] ) { |
| 206 | continue; |
| 207 | } |
| 208 | $actions[] = [ |
| 209 | 'label' => $action['label'], |
| 210 | 'url' => $action['url'], |
| 211 | 'class' => 'job-dashboard-action-' . esc_attr( $action['name'] ), |
| 212 | ]; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in UI classes. |
| 217 | echo UI_Elements::actions( $buttons, $actions ); |
| 218 | |
| 219 | } |
| 220 | |
| 221 | |
| 222 | } |
| 223 |