Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a filter that disables promoted jobs #2808

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking it's fine to just call the filter in multiple places, no need for a new class property for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I am not sure I agree with this one. It will be easier to update when we change the default value. Also we will probably need to repeat the comments too if we want all filters to be documented.

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
Loading