gpo = $general_plugin_obg; } // __construct | FNC /* 1. ENQUEUE ADMIN | styles and scripts -------------------------------------------------------------------*/ /** * Register the stylesheets and JavaScript files for the admin area. * * @since 1.0.0 */ public function enqueue_styles_and_scripts( $hook_suffix ) { require 'amo-team-showcase-admin-enqueue.php'; } // enqueue_styles_and_scripts | FNC /*------------------------------------------------------------------- ▐ 2. ADMIN NOTICES / WARNINGS --------------------------------------------------------------------*/ /** * Shows "regenerate thumbnails" admin notice, if the notice is not disabled * * @since 1.0.0 */ public function activation_notice_regen_thumbnails() { $amo_team_system = get_option( $this->gpo->get_plugin_name() . '-system' ); if ( ! isset( $amo_team_system['thumb-notice'] ) || ! $amo_team_system['thumb-notice'] ) { $this->gpo->render_dependencies( $this, false); $this->renderer->set_variables( array( 'nonce' => wp_create_nonce( 'hide-regen-thumbnails-notice' ), ) ); echo $this->renderer->render( 'notice-thumbnails', 'specific' ); } // IF } // FNC /** * AJAX function to hide "regenerate thumbnails" admin notice, * which becomes visible on plugin's activation * * @since 1.0.0 */ public function hide_regen_thumbnails_notice() { check_ajax_referer( 'hide-regen-thumbnails-notice', 'security' ); $amo_team_system = get_option( $this->gpo->get_plugin_name() . '-system' ); $amo_team_system['thumb-notice'] = true; update_option( $this->gpo->get_plugin_name() . '-system', $amo_team_system ); wp_die(); } // FNC /** * Displays a warning if WP version is less than required one. * * @since 1.0.0 */ function wp_version_warning() { $current_screen = get_current_screen(); if ( $this->gpo->options_or_member_screen ) { if ( version_compare( $GLOBALS['wp_version'], '4.6', '<' ) ) { $this->gpo->render_dependencies( $this, false); $this->renderer->set_variables( array( 'notice-message' => sprintf( '%s: %s', __( 'Warning', 'amo-team' ), sprintf( __( 'Amo Team Showcase plugin requires at least WordPress version 4.6. You are running version %s. Please update WordPress.', 'amo-team' ), $GLOBALS['wp_version'], admin_url( 'update-core.php' ) ) ), 'notice-type' => 'warning', ) ); echo $this->renderer->render( 'notice-general', 'specific' ); } // IF | WP version } // IF | options_or_member_screen } // FNC /* 3. MAIN SANITIZATION FUNCTION | Before to save in DB -------------------------------------------------------------------*/ /** * Sanitization of admin form values (plugin options and member metaboxes), on form submission. * * @since 1.0.0 */ public function sanitize_form_input_values( $values_array, $metabox = false ) { $sanitized_vals = array(); $metabox_key = ''; $metabox_san_values = array(); $sanitize = true; /* Sanitize the values --------------------------------------------------------------------*/ foreach ( $values_array as $key => $val ) { // if we have multidimensional array from metabox field if ( ! $metabox && is_array($val) ) { foreach ( $val as $key2 => $metabox_vals ) { $metabox_san_values[] = $this->sanitize_form_input_values( $metabox_vals, true ); } // FOREACH $metabox_key = $key; } // IF array from metabox field // if no sanitization if ( false !== strpos( $key, 'nosan_' ) ) { $sanitize = false; $key = ( substr( $key, strlen( 'nosan_' ) ) ); } // if no sanitization if ( false !== strpos( $key, 'number__' ) ) { // number input type // delete 'number__' from the input name ($key) and sanitize its value $sanitized_vals[ ( substr( $key, strlen( 'number__' ) ) ) ] = $sanitize ? absint( $val ) : $val; } elseif ( false !== strpos( $key, 'text__' ) ) { // text input type // delete 'text__' from the input name ($key) and sanitize its value $sanitized_vals[ ( substr( $key, strlen( 'text__' ) ) ) ] = $sanitize ? sanitize_text_field( $val ) : trim( $val ); } elseif ( false !== strpos( $key, 'switcher__' ) ) { // text input type // delete 'switcher__' from the input name ($key) and sanitize its value $sanitized_vals[ ( substr( $key, strlen( 'switcher__' ) ) ) ] = $sanitize ? absint( $val ) : $val; } elseif ( false !== strpos( $key, 'select__' ) ) { // text input type // delete 'select__' from the input name ($key) and sanitize its value $sanitized_vals[ ( substr( $key, strlen( 'select__' ) ) ) ] = $sanitize ? sanitize_text_field( $val ) : $val; } // IF } // FOREACH // IF it was sanitization for metabox if ( $metabox ) { $metabox_san_values = $sanitized_vals; $sanitized_vals = array(); } else { if ( $metabox_key ) { $sanitized_vals[$metabox_key] = $metabox_san_values; } } // IF return $metabox ? $metabox_san_values : $sanitized_vals; } // sanitize_form_input_values | FNC /*------------------------------------------------------------------- ▐ 4. OPTIONS PAGE | And functionality related to it --------------------------------------------------------------------*/ /** * Adds plugin's options menu item to the admin panel. * * @since 1.0.0 */ public function add_plugin_options_menu() { // Adds plugin's options menu item to WP panel add_submenu_page( 'edit.php?post_type=amo-team', __( 'AMO Team Options', 'amo-team' ), __('Options', 'amo-team' ), 'manage_options', 'amo-team-options', array( $this, 'display_options_page' ) ); } // FNC /** * Displays plugin options page. * * @since 1.0.0 */ public function display_options_page() { $settings_notice = ''; $this->gpo->render_dependencies( $this, false); // Settings update/reset notice if ( isset( $_GET['settings-updated'] ) && 1 == $_GET['settings-updated'] ) { $settings_notice = 'settings-updated'; } else if ( isset( $_GET['settings-reset'] ) && 1 == $_GET['settings-reset'] ) { $settings_notice = 'settings-reset'; } $this->renderer->set_variables( array( 'settings_notice' => ( $this->renderer->render( 'options-page/' . $settings_notice, $this->main_subviews_folder ) ), 'panel_buttons' => $this->renderer->render( 'options-page/panel__buttons', $this->main_subviews_folder ), 'nav-tabs' => $this->renderer->render( 'options-page/nav-tabs', $this->main_subviews_folder, array( 'name' => 'args', // wil be $args in the template 'value' => array( 'general-t' => array( _x( 'General', 'Navigation tab title.', 'amo-team' ), 'icon-settings' ), // the second value is an icon name 'thumbs-t' => array( _x( 'Thumbnails', 'Navigation tab title.', 'amo-team' ), 'icon-layout-grid2' ), 'panel-t' => array( _x( 'Panel', 'Navigation tab title.', 'amo-team' ), 'icon-layout-width-default-alt' ), 'shortcodes-t' => array( _x( 'Shortcodes', 'Navigation tab title.', 'amo-team' ), 'icon-shortcode' ), 'misc-t' => array( _x( 'Misc', 'Abridgement from Miscellaneous. Navigation tab title.', 'amo-team' ), 'icon-panel' ), ) ) ), 'tab-panes' => $this->renderer->assemble_sub_views_for_page( 'options-page', $this->main_subviews_folder, array( 'name' => 'opts', // wil be $opts in the template 'value' => get_option( 'amo-team-showcase-options' ) ) ), 'form_nonce' => wp_nonce_field( 'amo_team_options_save', 'amo_team_options_nonce', true, false ), 'plugin_version' => $this->gpo->get_version(), ) ); echo $this->renderer->render( 'options-page' ); } // create_options_page | FNC /** * Saves and resets form values/settings on plugin's options page. * * @since 1.0.0 */ public function save_plugin_options() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( __( 'You are not allowed to be on this page.', 'amo-team' ) ); } // check options form nonce check_admin_referer( 'amo_team_options_save', 'amo_team_options_nonce' ); $settings_status = ''; // If option's "Reset All Settings" button is pressed if ( 'reset' == $_POST['submit-type'] ) { // Initialize the renderer with admin folder parameter $renderer = amo_team_showcase_renderer( 'admin' ); // load predefined, default values/data from files update_option( $this->gpo->get_plugin_name() . '-css-styles', $renderer->fetch_arguments( 'complied-css', 'activation' ) ); update_option( $this->gpo->get_plugin_name() . '-options', $renderer->fetch_arguments( 'options-data', 'activation' ) ); $settings_status = '&settings-reset=1'; // If option's "Save Changes" button is pressed } else if ( 'save' == $_POST['submit-type'] ) { // get only options form values, slice off the first 3 array items (WP's form service information) $options_vals = array_slice($_POST, 4); // Sanitize form values $sanitized_vals = $this->sanitize_form_input_values( $options_vals ); // Save/Update plugin options update_option( $this->gpo->get_plugin_name() . '-options', $sanitized_vals ); // Save/Update plugin css styles (created from options settings) update_option( $this->gpo->get_plugin_name() . '-css-styles', $this->assemble_css_styles_from_options( $sanitized_vals ) ); $settings_status = '&settings-updated=1'; } // IF | "Reset All Settings" / "Save Changes" button // redirect back to plugin options page wp_redirect( admin_url('edit.php?post_type=amo-team&page=amo-team-options' . $settings_status ) ); exit; } // save_plugin_options | FNC /** * Assemble CSS styles from plugin options/settings * * @since 1.0.0 */ protected function assemble_css_styles_from_options( $options ) { $this->gpo->render_dependencies( $this, false, false); $this->renderer->set_variables( array( 'options' => $options, ) ); return preg_replace( '/[\r\n\t\f\v]{1,}/', '', $this->renderer->render( 'css-styles', 'specific' ) ); } // FNC /*------------------------------------------------------------------- ▐ 5. TEAM MEMBER METABOXES AND SETTINGS | Edit/New member screen --------------------------------------------------------------------*/ /** * Add/Init team member metabox with settings | Edit/New team member * * @since 1.0.0 */ public function team_member_meta_box_init() { add_meta_box( 'amo-team-member-settings', // Meta box ID __( 'Team Member Settings', 'amo-team' ), // Title of the meta box. array( $this, 'display_member_settings_meta_box' ), // $callback 'amo-team', // $screen - post type, page 'normal', // The context within the screen where the boxes should display. 'high' // Priority ); } // team_member_meta_box_init | FNC /** * Set available post formats | Edit/New team member * * @since 1.0.0 */ public function set_post_formats_team_member_post_type() { global $typenow; if ( 'amo-team' == $typenow ) { add_theme_support( 'post-formats', array( 'image', 'quote', 'link' ) ); } //IF } // remove_post_formats_from_team_member_post_type | FNC /** * Display metabox | Edit/New team member * * @since 1.0.0 */ public function display_member_settings_meta_box( $post ) { $this->gpo->render_dependencies( $this, false); //nonce for security wp_nonce_field( 'amo_team_member_metabox', 'amo_team_member_metabox_nonce' ); $this->renderer->set_variables( array( 'tab-panes' => $this->renderer->assemble_sub_views_for_page( 'member-meta-box', $this->main_subviews_folder, array( array( 'name' => 'opts', // wil be $opts in the template 'value' => get_post_meta( $post->ID, 'amo-team-member-metabox', true ) ), array( 'name' => 'metabox', // wil be $opts in the template 'value' => 'amo-team-member-metabox' ), ) ), // tab-panes ) ); //set_variables echo $this->renderer->render( 'member-meta-box' ); } // create_member_settings_meta_box | FNC /** * Save member metabox form values/data to database * * @since 1.0.0 */ public function team_member_meta_box_save( $post_id, $post, $update ) { // verify if this is not an auto save routine. // If the post has not been updated, we don't do anything if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $post_id; } //check nonce for security if ( ! isset($_POST['amo-team-member-metabox']) || ! wp_verify_nonce( $_POST['amo_team_member_metabox_nonce'], 'amo_team_member_metabox' ) ) { return false; } // Get the post type object. $post_type = get_post_type_object( $post->post_type ); // Check if the current user has permission to edit the post type. if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) ) { return false; } // Sanitize metabox values $values = $this->sanitize_form_input_values( $_POST['amo-team-member-metabox'] ); // Add post format entry to the array of values $values['post_format'] = get_post_format( $post_id ); // Save/Update post's meta data update_post_meta( $post_id, 'amo-team-member-metabox', $values ); } // team_member_meta_box_save | FNC /*------------------------------------------------------------------- ▐ 6. ADD ID, THUMB COLUMNS | All Member screen --------------------------------------------------------------------*/ /** * Adds 2 custom columns, on 'All Members' screen * * @since 1.0.0 */ public function set_custom_post_column_names( $defaults ) { $defaults['amoteam_id'] = __( 'Member Shortcode', 'amo-team' ); $defaults['amoteam_thumb'] = ''; return $defaults; } // set_custom_post_column_names | FNC /** * Renders mentioned in previous function custom columns on 'All Members' screen * * @since 1.0.0 */ public function render_custom_post_column_names( $column_title, $post_id ) { switch ( $column_title ) { case 'amoteam_id': echo '[amo_member id="' . $post_id . '" item-width="250" align="left" item-margin="20" full-width="yes" panel="right"]'; break; case 'amoteam_thumb': if ( has_post_thumbnail() ) { $attachment_array = wp_get_attachment_image_src( get_post_thumbnail_id(), 'thumbnail', true ); // render thumbnail $this->gpo->render_dependencies( $this, false); $this->renderer->set_variables( array( 'img_url' => $attachment_array[0], ) ); echo $this->renderer->render( 'general/post-list-thumb', $this->main_subviews_folder ); } break; default: break; } // SWITCH } // render_custom_post_column_names | FNC /*------------------------------------------------------------------- ▐ 7. CATEGORY FILTER | team members list --------------------------------------------------------------------*/ /** * Display a custom taxonomy dropdown filter in admin | Custom post type list * * @since 1.0.0 */ public function filter_post_type_by_taxonomy() { global $typenow; if ( $typenow == 'amo-team' ) { $taxonomy = 'amo-team-category'; $selected = isset( $_GET[ $taxonomy ] ) ? $_GET[ $taxonomy ] : ''; $info_taxonomy = get_taxonomy( $taxonomy ); wp_dropdown_categories( array( 'show_option_all' => __( "Show All {$info_taxonomy->label}", 'amo-team' ), 'taxonomy' => $taxonomy, 'name' => $taxonomy, 'orderby' => 'name', 'selected' => $selected, 'show_count' => true, 'hide_empty' => true, ) ); }; // IF 'amo-team' } // FNC /** * Filter posts by taxonomy in admin | Custom post type list * * @since 1.0.0 */ public function convert_id_to_term_in_query( $query ) { global $typenow; if ( $typenow == 'amo-team' ) { $current_screen = get_current_screen(); if ( $current_screen->id == 'edit-amo-team' ) { $taxonomy = 'amo-team-category'; $q_vars = &$query->query_vars; if ( isset( $q_vars[ $taxonomy ] ) && is_numeric( $q_vars[ $taxonomy ] ) && $q_vars[ $taxonomy ] != 0 ) { $term = get_term_by( 'id', $q_vars[ $taxonomy ], $taxonomy ); $q_vars[ $taxonomy ] = $term->slug; } } // IF current_screen == 'edit-amo-team' } } // FNC /*------------------------------------------------------------------- ▐ 8. ADD 'ID' COLUMN | Amo team Categories screen --------------------------------------------------------------------*/ /** * Adds ID column header, on amo team categories screen * * @since 1.0.0 */ public function categories_columns_header( $columns ) { $columns['category-id'] = __( 'ID', 'amo-team' ); return $columns; } // FNC /** * Outputs category ID in the column, on amo team categories screen * * @since 1.0.0 */ public function categories_columns_row( $argument, $column_name, $category_id ) { if ( $column_name == 'category-id' ) { return $category_id; } } // FNC /** * Aligns custom ID column in our taxonomy/category list * by adding WP native classes to it. * * @since 1.0.0 */ public function align_taxonomy_custom_id_column( ) { ?> gpo->render_dependencies( $this, false); // if "edit_form_after_editor" action ($var is $post) if ( is_object( $var ) ) { // set variables for shortcodes modal block $this->renderer->set_variables( array( 'link_title' => __( "Shortcode's documentation", 'amo-team' ), array( 'title' => _x( 'Text Block', 'Shortcodes generating block', 'amo-team' ), 'link' => '//amothemo.com/docs/amo-team-showcase-documentation/' . Amo_Team_Showcase_AVH::get_lang_from_locale('/') . '#sc-text-block', 'type' => 'bio', 'class' => '{p}icon-doc-text', ), array( 'title' => _x( 'Skills', 'Shortcodes generating block', 'amo-team' ), 'link' => '//amothemo.com/docs/amo-team-showcase-documentation/' . Amo_Team_Showcase_AVH::get_lang_from_locale('/') . '#sc-skills', 'type' => 'skills', 'class' => '{p}icon-graduation-cap {p}icon-margin-fix', ), array( 'title' => _x( 'Team', 'Shortcodes generating block', 'amo-team' ), 'link' => '//amothemo.com/docs/amo-team-showcase-documentation/' . Amo_Team_Showcase_AVH::get_lang_from_locale('/') . '#sc-amoteam', 'type' => 'team', 'class' => '{p}icon-users {p}icon-margin-fix', ), ) ); // End set_variables echo $this->renderer->render( 'post/sc-button-modal', $this->main_subviews_folder ); } else { //"media_buttons" action echo $this->renderer->render( 'post/shortcodes-button', $this->main_subviews_folder ); } } // add_amo_team_button_wp_editor | FNC /* 10. PLUGIN "ACTION" LINKS -------------------------------------------------------------------*/ /** * Add plugin action URL links | activate/deactivate plugins screen * * @return array plugin links * @since 1.0.0 */ public function add_plugin_actions_links( $links ) { $this->gpo->render_dependencies( null, false, true ); $links[] = sprintf( '%s', admin_url( 'edit.php?post_type=amo-team&page=amo-team-options' ), __( 'Options', 'amo-team' ) ); $links[] = sprintf( '%s', '//amothemo.com/docs/amo-team-showcase-documentation/' . Amo_Team_Showcase_AVH::get_lang_from_locale() . '/#ds-quic-start', __( 'Where to start?', 'amo-team' ) ); return $links; } /* 11. IMAGE SIZES IN MEDIA LIBRARY -------------------------------------------------------------------*/ /** * Add new image size to the media library * * @param $sizes * * @return array image sizes array * @since 1.0.0 */ public function image_sizes_names( $sizes ) { $added_sizes = array( AMO_TEAM_SHOWCASE_CSS_PREFIX . "general" => __( "AMO Team general"), ); return $sizes + (array)$added_sizes; } // FNC /* 12. ADD REMOVABLE QUERY ARGS -------------------------------------------------------------------*/ /** * Add certain plugin's query args to WP removable URL query arguments * * @return array $removable_query_args * @since 1.0.0 */ public function add_plugin_removable_query_args( $removable_query_args ) { if ( ! in_array( 'settings-reset', $removable_query_args ) ) { $removable_query_args[] = 'settings-reset'; } return $removable_query_args; } // FNC /* 13. REMOVE VIEW LINK | All Members screen -------------------------------------------------------------------*/ /** * Removes "view" link from available links/actions * for team member on All Members screen * * @return array $actions List of links * @since 1.0.0 */ function all_members_screen_remove_actions( $actions, $post ) { if ( $post->post_type == 'amo-team' ) { unset( $actions['view'] ); } return $actions; } // FNC } // Amo_Team_Showcase_Admin | CLASS