-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b5f57a
commit 017990f
Showing
4 changed files
with
196 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
/** | ||
* Admin page settings | ||
* | ||
* @package Pronamic\WordPressCloudflare | ||
*/ | ||
|
||
if ( ! defined( 'ABSPATH' ) ) { | ||
exit; | ||
} | ||
|
||
?> | ||
<div class="wrap"> | ||
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1> | ||
|
||
<form method="post" action="options.php"> | ||
<?php settings_fields( 'pronamic_post_expiration' ); ?> | ||
|
||
<?php do_settings_sections( 'pronamic_post_expiration' ); ?> | ||
|
||
<?php submit_button(); ?> | ||
</form> | ||
</div> |
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,71 @@ | ||
<?php | ||
/** | ||
* Settings field post types | ||
* | ||
* @author Pronamic <[email protected]> | ||
* @copyright 2005-2024 Pronamic | ||
* @license GPL-2.0-or-later | ||
* @package Pronamic\WordPressCloudflare | ||
*/ | ||
|
||
$post_type_objects = get_post_types( | ||
[ | ||
'public' => true, | ||
], | ||
'objects' | ||
); | ||
|
||
?> | ||
<style type="text/css"> | ||
.form-table .widefat th, | ||
.form-table .widefat td { | ||
padding: 8px 10px; | ||
} | ||
</style> | ||
|
||
<table class="widefat"> | ||
<thead> | ||
<tr> | ||
<th><?php esc_html_e( 'Post type', 'pronamic-post-expiration' ); ?></th> | ||
<th><?php esc_html_e( 'Label', 'pronamic-post-expiration' ); ?></th> | ||
<th><?php esc_html_e( 'Support', 'pronamic-post-expiration' ); ?></th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
|
||
<?php foreach ( $post_type_objects as $post_type_info ) : ?> | ||
|
||
<tr> | ||
<td> | ||
<code><?php echo \esc_html( $post_type_info->name ); ?></code> | ||
</td> | ||
<td> | ||
<?php echo \esc_html( $post_type_info->label ); ?> | ||
</td> | ||
<td> | ||
<?php | ||
|
||
$supports = \get_all_post_type_supports( $post_type_info->name ); | ||
|
||
$checked = false; | ||
$disabled = false; | ||
|
||
if ( post_type_supports( $post_type_info->name, 'expiration' ) ) { | ||
$checked = true; | ||
$disabled = true; | ||
|
||
if ( isset( $supports['expiration']['source'] ) ) { | ||
$disabled = ( 'option' !== $supports['expiration']['source'] ); | ||
} | ||
} | ||
|
||
?> | ||
<input type="checkbox" name="pronamic_post_expiration_post_types[]" value="<?php echo \esc_attr( $post_type_info->name ); ?>" <?php checked( $checked ); ?> <?php disabled( $disabled ); ?> /> | ||
</td> | ||
</tr> | ||
|
||
<?php endforeach; ?> | ||
|
||
</tbody> | ||
</table> |
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,77 @@ | ||
<?php | ||
/** | ||
* Settings controller | ||
* | ||
* @author Pronamic <[email protected]> | ||
* @copyright 2005-2024 Pronamic | ||
* @license GPL-2.0-or-later | ||
* @package Pronamic\PostExpiration | ||
*/ | ||
|
||
namespace Pronamic\PostExpiration; | ||
|
||
/** | ||
* Settings controller class | ||
*/ | ||
final class SettingsController { | ||
/** | ||
* Setup. | ||
*/ | ||
public function setup() { | ||
\add_action( 'init', [ $this, 'init' ] ); | ||
|
||
\add_action( 'admin_init', [ $this, 'admin_init' ] ); | ||
|
||
\add_action( 'admin_menu', [ $this, 'admin_menu' ] ); | ||
} | ||
|
||
/** | ||
* Initialize. | ||
*/ | ||
public function init() { | ||
\register_setting( | ||
'pronamic_post_expiration', | ||
'pronamic_post_expiration_post_types' | ||
); | ||
} | ||
|
||
/** | ||
* Admin initialize. | ||
*/ | ||
public function admin_init() { | ||
\add_settings_section( | ||
'pronamic_post_expiration_general', | ||
\__( 'General', 'pronamic-post-expiration' ), | ||
function () { }, | ||
'pronamic_post_expiration' | ||
); | ||
|
||
\add_settings_field( | ||
'pronamic_post_expiration_post_types', | ||
\__( 'Post types', 'pronamic-moneybird' ), | ||
function () { | ||
include __DIR__ . '/../admin/settings-field-post-types-support.php'; | ||
}, | ||
'pronamic_post_expiration', | ||
'pronamic_post_expiration_general' | ||
); | ||
} | ||
|
||
/** | ||
* Admin menu. | ||
* | ||
* @link https://developer.wordpress.org/reference/functions/add_options_page/ | ||
* @return void | ||
*/ | ||
public function admin_menu() { | ||
\add_options_page( | ||
\__( 'Pronamic Post Expiration', 'pronamic-post-expiration' ), | ||
\__( 'Pronamic Post Expiration', 'pronamic-post-expiration' ), | ||
'manage_options', | ||
'pronamic_post_expiration', | ||
function () { | ||
include __DIR__ . '/../admin/page-settings.php'; | ||
} | ||
); | ||
} | ||
} |