action_key, array( $this, 'switch_legacy' ) );
}
public function switch_legacy() {
if ( ! $this->can_disable() || ! wp_verify_nonce( $_GET['_nonce'], $this->action_key ) ) {
wp_die( __( 'You not allowed to do this.', 'jet-engine' ), __( 'Error', 'jet-engine' ) );
}
$is_disabled = $this->is_disabled();
$is_disabled = ! $is_disabled;
update_option( $this->option_key, $is_disabled, true );
wp_die(
sprintf(
__( 'Legacy option switched. Please reload the page where you clicked the link to apply changes. To switch legacy options back - %s', 'jet-engine' ),
$this->get_legacy_switch_link( __( 'click here', 'jet-engine' ) )
),
__( 'Legacy Options Switched', 'jet-engine' ) );
}
public function get_notice() {
if ( $this->is_disabled() ) {
return sprintf(
__( 'Query options marked as legacy and disabled. To enable these options (not recommended) - %s', 'jet-engine' ),
$this->get_legacy_switch_link( __( 'click here', 'jet-engine' ), true )
);
} else {
return sprintf(
__( 'Query options inside Listing Grid marked as legacy. We recommend to use Query Builder instead. You can disable these options to optimize performance a bit. To disable legacy options - %s', 'jet-engine' ),
$this->get_legacy_switch_link( __( 'click here', 'jet-engine' ), true )
);
}
}
public function listing_has_query_notice( $listing ) {
if ( ! $this->is_disabled() ) {
return;
}
if ( ! $listing->listing_query_id ) {
_e( 'Please set the Query for the listing. You can do this by choosing listing item with Query source or by adding query in Custom Query section', 'jet-engine' );
}
}
public function get_legacy_switch_link( $text = '', $blank = false ) {
return sprintf(
'%3$s',
$this->get_legacy_switch_url(),
( $blank ? 'target="_blank"' : '' ),
$text
);
}
public function get_legacy_switch_url() {
return add_query_arg(
array(
'action' => $this->action_key,
'_nonce' => wp_create_nonce( $this->action_key ),
),
admin_url( 'admin.php' )
);
}
public function can_disable() {
return current_user_can( 'manage_options' );
}
public function is_disabled() {
return get_option( $this->option_key, false );
}
}