Skip to content

Commit

Permalink
Adds a filter that disables promoted jobs (#2808)
Browse files Browse the repository at this point in the history
  • Loading branch information
gikaragia committed Apr 23, 2024
2 parents f51a22e + 537bde6 commit 8684205
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
4 changes: 3 additions & 1 deletion assets/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,6 @@ jQuery(document).ready(function($) {
});
});

initializePromoteModals();
if ( job_manager_admin_params.promoted_jobs_enabled ) {
initializePromoteModals();
}
19 changes: 17 additions & 2 deletions includes/admin/class-wp-job-manager-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ class WP_Job_Manager_Admin {
*/
private $settings_page;

/**
* Whether promoted jobs are enabled.
*
* @var bool
*/
private $are_promoted_jobs_enabled;

/**
* Allows for accessing single instance of class. Class should only be constructed once per call.
*
Expand All @@ -58,7 +65,14 @@ public function __construct() {
include_once dirname( __FILE__ ) . '/class-wp-job-manager-cpt.php';
WP_Job_Manager_CPT::instance();

include_once dirname( __FILE__ ) . '/class-wp-job-manager-promoted-jobs-admin.php';
/**
* Documented in class-wp-job-manager.php
*/
$this->are_promoted_jobs_enabled = apply_filters( 'job_manager_enable_promoted_jobs', true );
if ( $this->are_promoted_jobs_enabled ) {
include_once dirname( __FILE__ ) . '/class-wp-job-manager-promoted-jobs-admin.php';
}

include_once dirname( __FILE__ ) . '/class-wp-job-manager-writepanels.php';
include_once dirname( __FILE__ ) . '/class-wp-job-manager-setup.php';
include_once dirname( __FILE__ ) . '/class-wp-job-manager-addons-landing-page.php';
Expand Down Expand Up @@ -144,11 +158,12 @@ public function admin_enqueue_scripts() {
],
'ajax_url' => admin_url( 'admin-ajax.php' ),
'search_users_nonce' => wp_create_nonce( 'search-users' ),
'promoted_jobs_enabled' => $this->are_promoted_jobs_enabled,
]
);
}

if ( \WP_Job_Manager_Post_Types::PT_LISTING === $screen->id && $screen->is_block_editor() ) { // Check if it's block editor in job post.
if ( \WP_Job_Manager_Post_Types::PT_LISTING === $screen->id && $screen->is_block_editor() && $this->are_promoted_jobs_enabled ) { // Check if it's block editor in job post.
$post = get_post();

if ( ! empty( $post ) ) {
Expand Down
14 changes: 12 additions & 2 deletions includes/class-wp-job-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,17 @@ public function __construct() {
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-data-exporter.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/admin/class-wp-job-manager-settings.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/class-wp-job-manager-com-api.php';
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/promoted-jobs/class-wp-job-manager-promoted-jobs.php';

/**
* Controls whether promoted jobs are enabled.
*
* @since $$next-version$$
*
* @param bool $enable_promoted_jobs Whether promoted jobs are enabled.
*/
if ( apply_filters( 'job_manager_enable_promoted_jobs', true ) ) {
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/promoted-jobs/class-wp-job-manager-promoted-jobs.php';
}

if ( is_admin() ) {
include_once JOB_MANAGER_PLUGIN_DIR . '/includes/admin/class-wp-job-manager-admin.php';
Expand Down Expand Up @@ -267,7 +277,7 @@ public static function maybe_schedule_cron_jobs() {
if ( ! wp_next_scheduled( 'job_manager_email_daily_notices' ) ) {
wp_schedule_event( time(), 'daily', 'job_manager_email_daily_notices' );
}
if ( ! wp_next_scheduled( WP_Job_Manager_Promoted_Jobs_Status_Handler::CRON_HOOK ) ) {
if ( class_exists( 'WP_Job_Manager_Promoted_Jobs_Status_Handler' ) && ! wp_next_scheduled( WP_Job_Manager_Promoted_Jobs_Status_Handler::CRON_HOOK ) ) {
wp_schedule_event( time(), 'hourly', WP_Job_Manager_Promoted_Jobs_Status_Handler::CRON_HOOK );
}
}
Expand Down

0 comments on commit 8684205

Please sign in to comment.