| 1 |
<?php |
| 2 |
/** |
| 3 |
* Provide a admin area view for the plugin |
| 4 |
* |
| 5 |
* This file is used to add the admin-facing aspects of the plugin. |
| 6 |
* |
| 7 |
* @link catchplugins.com |
| 8 |
* @since 1.0.0 |
| 9 |
* |
| 10 |
* @package Catch_Gallery |
| 11 |
* @subpackage Catch_Gallery/admin |
| 12 |
*/ |
| 13 |
|
| 14 |
if ( ! function_exists( 'catch_gallery_add_plugin_settings_menu' ) ) : |
| 15 |
function catch_gallery_add_plugin_settings_menu() { |
| 16 |
add_menu_page( |
| 17 |
esc_html__( 'Catch Gallery', 'catch-gallery' ), //page title |
| 18 |
esc_html__( 'Catch Gallery', 'catch-gallery' ), //menu title |
| 19 |
'edit_posts', //capability needed |
| 20 |
'catch-gallery', //menu slug (and page query url) |
| 21 |
'catch_gallery_settings', |
| 22 |
'dashicons-format-gallery', |
| 23 |
'99.01564' |
| 24 |
); |
| 25 |
} |
| 26 |
endif; // catch_gallery_add_plugin_settings_menu |
| 27 |
add_action( 'admin_menu', 'catch_gallery_add_plugin_settings_menu' ); |
| 28 |
|
| 29 |
|
| 30 |
if ( ! function_exists( 'catch_gallery_settings' ) ) : |
| 31 |
function catch_gallery_settings() { |
| 32 |
$child_theme = false; |
| 33 |
if ( ! current_user_can( 'edit_posts' ) ) { |
| 34 |
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'catch-gallery' ) ); |
| 35 |
} |
| 36 |
|
| 37 |
require_once plugin_dir_path( __FILE__ ) . 'catch-gallery-display.php'; |
| 38 |
} |
| 39 |
endif; // catch_gallery_settings |
| 40 |
|
| 41 |
if ( ! function_exists( 'catch_gallery_enqueue_styles' ) ) : |
| 42 |
/** |
| 43 |
* Enqueue Admin CSS |
| 44 |
*/ |
| 45 |
function catch_gallery_enqueue_styles() { |
| 46 |
if( isset( $_GET['page'] ) && 'catch-gallery' == $_GET['page'] ) { |
| 47 |
wp_enqueue_style( 'catch-gallery-dashboard', plugin_dir_url( __FILE__ ) . 'css/admin-dashboard.css', array(), CATCH_GALLERY_VERSION, 'all' ); |
| 48 |
|
| 49 |
wp_enqueue_script( 'minHeight', plugin_dir_url( __FILE__ ) . 'js/jquery.matchHeight.min.js', array( 'jquery' ), CATCH_GALLERY_VERSION, false ); |
| 50 |
|
| 51 |
wp_enqueue_script( 'catch-gallery-dashboard', plugin_dir_url( __FILE__ ) . 'js/admin.js', array( 'jquery','jquery-ui-tooltip' ), CATCH_GALLERY_VERSION, false ); |
| 52 |
} |
| 53 |
} |
| 54 |
endif; // catch_gallery_enqueue_styles |
| 55 |
add_action( 'admin_enqueue_scripts', 'catch_gallery_enqueue_styles' ); |
| 56 |
|
| 57 |
if( ! function_exists( 'catch_gallery_register_settings' ) ): |
| 58 |
/** |
| 59 |
* Catch gallery: register_settings |
| 60 |
* Catch gallery Register Settings |
| 61 |
*/ |
| 62 |
function catch_gallery_register_settings() { |
| 63 |
register_setting( |
| 64 |
'catch-gallery-group', |
| 65 |
'catch_gallery_options', |
| 66 |
'catch_gallery_sanitize_callback' |
| 67 |
); |
| 68 |
} |
| 69 |
endif; |
| 70 |
add_action( 'admin_init', 'catch_gallery_register_settings' ); |
| 71 |
|
| 72 |
if( ! function_exists( 'catch_gallery_sanitize_checkbox' ) ): |
| 73 |
function catch_gallery_sanitize_checkbox( $checked ) { |
| 74 |
// Boolean check. |
| 75 |
return ( ( isset( $checked ) && true == $checked ) ? true : false ); |
| 76 |
} |
| 77 |
endif; |
| 78 |
|
| 79 |
if( ! function_exists( 'catch_gallery_sanitize_callback' ) ): |
| 80 |
/** |
| 81 |
*Catch gallery: sanitize_callback |
| 82 |
* Catch gallery Sanitization function callback |
| 83 |
* |
| 84 |
* @param array $input Input data for sanitization. |
| 85 |
*/ |
| 86 |
function catch_gallery_sanitize_callback( $input ) { |
| 87 |
$defaults = catch_gallery_default_options(); |
| 88 |
|
| 89 |
if ( isset( $input['reset'] ) && $input['reset'] ) { |
| 90 |
//If reset, restore defaults |
| 91 |
return $defaults; |
| 92 |
} |
| 93 |
|
| 94 |
// Verify the nonce before proceeding. |
| 95 |
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) |
| 96 |
|| ( ! isset( $_POST['catch_gallery_nounce'] ) |
| 97 |
|| ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['catch_gallery_nounce'] ) ), basename( __FILE__ ) ) ) |
| 98 |
|| ( ! check_admin_referer( basename( __FILE__ ), 'catch_gallery_nounce' ) ) ) { |
| 99 |
if ( $input ) { |
| 100 |
|
| 101 |
if ( isset( $input['carousel_enable'] ) && $input['carousel_enable'] ) { |
| 102 |
$input['carousel_enable'] = catch_gallery_sanitize_checkbox( $input['carousel_enable'] ); |
| 103 |
} |
| 104 |
|
| 105 |
if ( isset( $input['carousel_background_color'] ) && $input['carousel_background_color'] ) { |
| 106 |
$input['carousel_background_color'] = sanitize_key( $input['carousel_background_color'] ); |
| 107 |
} |
| 108 |
|
| 109 |
if ( isset( $input['carousel_display_exif'] ) && $input['carousel_display_exif'] ) { |
| 110 |
$input['carousel_display_exif'] = catch_gallery_sanitize_checkbox( $input['carousel_display_exif'] ); |
| 111 |
} |
| 112 |
|
| 113 |
if ( isset( $input['comments_display'] ) && $input['comments_display'] ) { |
| 114 |
$input['comments_display'] = catch_gallery_sanitize_checkbox( $input['comments_display'] ); |
| 115 |
} |
| 116 |
|
| 117 |
if ( isset( $input['fullsize_display'] ) && $input['fullsize_display'] ) { |
| 118 |
$input['fullsize_display'] = catch_gallery_sanitize_checkbox( $input['fullsize_display'] ); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 122 |
return $input; |
| 123 |
} // End if(). |
| 124 |
return 'Invalid Nonce'; |
| 125 |
} |
| 126 |
endif; |
| 127 |
|
| 128 |
if ( ! function_exists( 'catch_gallery_action_links' ) ) : |
| 129 |
/** |
| 130 |
* Catch_IDs: catch_gallery_action_links |
| 131 |
* Catch_IDs Settings Link function callback |
| 132 |
* |
| 133 |
* @param arrray $links Link url. |
| 134 |
* |
| 135 |
* @param arrray $file File name. |
| 136 |
*/ |
| 137 |
function catch_gallery_action_links( $links, $file ) { |
| 138 |
if ( $file === 'catch-gallery/catch-gallery.php' ) { |
| 139 |
$settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=catch-gallery' ) ) . '">' . esc_html__( 'Settings', 'catch-gallery' ) . '</a>'; |
| 140 |
|
| 141 |
array_unshift( $links, $settings_link ); |
| 142 |
} |
| 143 |
return $links; |
| 144 |
} |
| 145 |
endif; // catch_gallery_action_links |
| 146 |
add_filter( 'plugin_action_links', 'catch_gallery_action_links', 10, 2 ); |