| 1 |
<?php |
| 2 |
/** |
| 3 |
* PropertyHive Settings Page/Tab |
| 4 |
* |
| 5 |
* @author PropertyHive |
| 6 |
* @category Admin |
| 7 |
* @package PropertyHive/Admin |
| 8 |
* @version 1.0.0 |
| 9 |
*/ |
| 10 |
|
| 11 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 12 |
|
| 13 |
if ( ! class_exists( 'PH_Settings_Page' ) ) : |
| 14 |
|
| 15 |
/** |
| 16 |
* PH_Settings_Page |
| 17 |
*/ |
| 18 |
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound -- Legacy public global class PH_Settings_Page; preserving the existing PH_* class name is required for plugin and extension compatibility. |
| 19 |
class PH_Settings_Page { |
| 20 |
|
| 21 |
protected $id = ''; |
| 22 |
protected $label = ''; |
| 23 |
|
| 24 |
/** |
| 25 |
* Add this page to settings |
| 26 |
*/ |
| 27 |
public function add_settings_page( $pages ) { |
| 28 |
$pages[ $this->id ] = $this->label; |
| 29 |
|
| 30 |
return $pages; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Get settings array |
| 35 |
* |
| 36 |
* @return array |
| 37 |
*/ |
| 38 |
public function get_settings() { |
| 39 |
return array(); |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Get sections |
| 44 |
* |
| 45 |
* @return array |
| 46 |
*/ |
| 47 |
public function get_sections() { |
| 48 |
return array(); |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* Output sections |
| 53 |
*/ |
| 54 |
public function output_sections() { |
| 55 |
global $current_section; |
| 56 |
|
| 57 |
$sections = $this->get_sections(); |
| 58 |
|
| 59 |
if ( empty( $sections ) ) |
| 60 |
return; |
| 61 |
|
| 62 |
echo '<ul class="subsubsub">'; |
| 63 |
|
| 64 |
$array_keys = array_keys( $sections ); |
| 65 |
|
| 66 |
foreach ( $sections as $id => $label ) |
| 67 |
echo '<li> <a href="' . esc_url(admin_url( 'admin.php?page=ph-settings&tab=' . $this->id . '§ion=' . sanitize_title( $id ) ) ) . '" class="' . ( $current_section == $id ? 'current' : '' ) . '">' . esc_html($label) . '</a> ' . ( end( $array_keys ) == $id ? '' : '| ' ) . ' </li>'; |
| 68 |
|
| 69 |
echo '</ul><br class="clear" />'; |
| 70 |
} |
| 71 |
|
| 72 |
/** |
| 73 |
* Output the settings |
| 74 |
*/ |
| 75 |
public function output() { |
| 76 |
$settings = $this->get_settings(); |
| 77 |
|
| 78 |
PH_Admin_Settings::output_fields( $settings ); |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Save settings |
| 83 |
*/ |
| 84 |
public function save() { |
| 85 |
if ( ! current_user_can( 'manage_options' ) || ! isset( $_REQUEST['_wpnonce'] ) || ! is_string( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ), 'propertyhive-settings' ) ) { |
| 86 |
return; |
| 87 |
} |
| 88 |
|
| 89 |
global $current_section; |
| 90 |
|
| 91 |
$settings = $this->get_settings(); |
| 92 |
PH_Admin_Settings::save_fields( $settings ); |
| 93 |
|
| 94 |
if ( $current_section ) |
| 95 |
do_action( 'propertyhive_update_options_' . $this->id . '_' . $current_section ); |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
endif; |