-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from Emilia-Capital/settings/exclude-post-types
Add a settings popover to exclude post-types from tracking
- Loading branch information
Showing
7 changed files
with
219 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
document.getElementById( 'prpl-settings-form' ).addEventListener( 'submit', function( event ) { | ||
event.preventDefault(); | ||
const form = new FormData( this ); | ||
const data = form.getAll( 'prpl-settings-post-types-include[]' ); | ||
|
||
// Save the options. | ||
progressPlannerAjaxRequest( { | ||
url: progressPlanner.ajaxUrl, | ||
data: { | ||
action: 'progress_planner_save_cpt_settings', | ||
_ajax_nonce: progressPlanner.nonce, | ||
include_post_types: data, | ||
}, | ||
successAction: () => { | ||
window.location.reload(); | ||
}, | ||
} ); | ||
|
||
document.getElementById( 'submit-include-post-types' ).disabled = true; | ||
document.getElementById( 'submit-include-post-types' ).innerHTML = progressPlanner.l10n.saving; | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** | ||
* Settings popup. | ||
* | ||
* @package Progress_Planner | ||
*/ | ||
|
||
namespace Progress_Planner\Popups; | ||
|
||
use Progress_Planner\Activities\Content_Helpers; | ||
|
||
/** | ||
* Settings popup. | ||
*/ | ||
final class Settings extends Popup { | ||
|
||
/** | ||
* The popover ID. | ||
* | ||
* @var string | ||
*/ | ||
protected $id = 'settings'; | ||
|
||
/** | ||
* Render the triggering button. | ||
* | ||
* @return void | ||
*/ | ||
public function render_button() { | ||
?> | ||
<!-- The triggering button. --> | ||
<button class="prpl-info-icon" popovertarget="prpl-popover-<?php echo \esc_attr( $this->id ); ?>"> | ||
<span class="dashicons dashicons-admin-generic"></span> | ||
<span class="screen-reader-text"><?php \esc_html_e( 'Settings', 'progress-planner' ); ?> | ||
</button> | ||
<?php | ||
} | ||
|
||
/** | ||
* Render the widget content. | ||
* | ||
* @return void | ||
*/ | ||
protected function the_content() { | ||
$saved_settings = Content_Helpers::get_post_types_names(); | ||
$post_types = \array_filter( \get_post_types( [ 'public' => true ] ), 'is_post_type_viewable' ); | ||
unset( $post_types['attachment'] ); | ||
unset( $post_types['elementor_library'] ); // Elementor templates are not a post type we want to track. | ||
?> | ||
|
||
<h2><?php \esc_html_e( 'Settings', 'progress-planner' ); ?></h2> | ||
|
||
<form id="prpl-settings-form"> | ||
<h3><?php \esc_html_e( 'Post Types', 'progress-planner' ); ?></h3> | ||
<p><?php \esc_html_e( 'Select the post types you want to include in activity scores. This setting will affect which post-type activities get tracked.', 'progress-planner' ); ?></p> | ||
<?php foreach ( $post_types as $post_type ) : ?> | ||
<label> | ||
<input | ||
type="checkbox" | ||
name="prpl-settings-post-types-include[]" | ||
value="<?php echo \esc_attr( $post_type ); ?>" | ||
<?php checked( \in_array( $post_type, $saved_settings, true ) ); ?> | ||
/> | ||
<?php echo \esc_html( \get_post_type_object( $post_type )->labels->name ); ?> | ||
</label> | ||
<?php endforeach; ?> | ||
|
||
<button id="submit-include-post-types" class="button button-primary"><?php \esc_html_e( 'Save', 'progress-planner' ); ?></button> | ||
</form> | ||
<?php | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters