*/ class DSAMM_Revision_Ajax_Action { function __construct() { } /** * * Menu item edit hook action * * @version 1.0.2 * @author theDotstore */ public static function dsamm_menu_edit_action_method_own() { check_ajax_referer( 'dsamm_ajax_value_nonce', 'security' ); $return_data = array(); // Ensure the current user has access if ( !current_user_can( 'edit_posts' ) ) { $return_data['error'] = esc_html__( 'Unauthorized access.', 'advance-menu-manager' ); echo wp_json_encode( $return_data ); exit; } $action = filter_input( INPUT_POST, 'action', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_id = filter_input( INPUT_POST, 'post_id', FILTER_SANITIZE_NUMBER_INT ); $post_slug = filter_input( INPUT_POST, 'post_slug', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_title = filter_input( INPUT_POST, 'post_title', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_author = filter_input( INPUT_POST, 'post_author', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_category_old = filter_input( INPUT_POST, 'post_category_old', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_category_new = filter_input( INPUT_POST, 'post_category_new', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_template = filter_input( INPUT_POST, 'post_template', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); if ( 'my_action_for_popup_menu_item_edit' === $action && !empty( $post_id ) && !empty( $post_slug ) ) { $update_my_post = array( 'ID' => $post_id, 'post_title' => $post_title, 'post_author' => $post_author, 'post_name' => $post_slug, ); wp_update_post( $update_my_post ); if ( !empty( $_POST['post_category'] ) ) { $old_cat_id_array = array_map( 'intval', explode( ',', $post_category_old ) ); $post_category_new = ( isset( $post_category_new ) ? $post_category_new : '' ); parse_str( $post_category_new, $new_cat_id_array ); $new_cat_id_array = array_map( 'intval', $new_cat_id_array['amm_post_set_category'] ); $cat_update = ''; //update category wp_remove_object_terms( $post_id, $old_cat_id_array, 'category' ); wp_set_object_terms( $post_id, $new_cat_id_array, 'category' ); $cate_name = ''; $i = 1; if ( !empty( $new_cat_id_array ) ) { foreach ( $new_cat_id_array as $cate_id ) { if ( $i === 1 ) { $cate_name .= get_cat_name( $cate_id ); } else { $cate_name .= ',' . get_cat_name( $cate_id ); } $i++; } $return_data['cat_id'] = implode( ',', $new_cat_id_array ); } else { $return_data['cat_id'] = "-"; } $return_data['cat_name'] = $cate_name; $return_data['post'] = 'true'; } else { if ( !empty( $post_template ) ) { $return_data['page'] = 'true'; update_post_meta( $post_id, '_wp_page_template', $post_template ); } } $get_current_post = get_post( $post_id ); $return_data['post_slug'] = $get_current_post->post_name; $return_data['sucess'] = esc_html__( 'Item has been successfully updated.', 'advance-menu-manager' ); } else { $return_data['error'] = esc_html__( 'Please try again later.', 'advance-menu-manager' ); } echo wp_json_encode( $return_data ); exit; } /** * * Add new menu item ajax action * * @version 1.0.2 * @author theDotstore */ public static function dsamm_add_new_post_action_method_own() { check_ajax_referer( 'dsamm_ajax_value_nonce', 'security' ); $return_data = array(); // Ensure the current user has access if ( !current_user_can( 'edit_posts' ) ) { $return_data['error'] = esc_html__( 'Unauthorized access.', 'advance-menu-manager' ); echo wp_json_encode( $return_data ); exit; } $action = filter_input( INPUT_POST, 'action', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_title = filter_input( INPUT_POST, 'post_title', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_author = filter_input( INPUT_POST, 'post_author', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_slug = filter_input( INPUT_POST, 'post_slug', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $item_post_type = filter_input( INPUT_POST, 'item_post_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $item_content = filter_input( INPUT_POST, 'item_content', FILTER_SANITIZE_SPECIAL_CHARS ); $item_content = html_entity_decode( $item_content ); $post_template = filter_input( INPUT_POST, 'post_template', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_category = filter_input( INPUT_POST, 'post_category', FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_REQUIRE_ARRAY ); if ( 'my_action_for_popup_add_new_post' === $action && !empty( $post_title ) && !empty( $post_author ) ) { $add_new_post = array( 'post_title' => $post_title, 'post_name' => $post_slug, 'post_status' => 'publish', 'post_author' => $post_author, 'post_type' => $item_post_type, 'post_content' => $item_content, ); if ( 'page' == $item_post_type ) { $new_post_id = wp_insert_post( $add_new_post ); $return_data['page'] = 'true'; update_post_meta( $new_post_id, '_wp_page_template', $post_template ); } else { $new_cat_id_array = ( isset( $_POST['post_category'] ) ? array_map( 'sanitize_text_field', wp_unslash( $_POST['post_category'] ) ) : array() ); $add_new_post = array_merge( $add_new_post, array( 'post_category' => $new_cat_id_array, ) ); $new_post_id = wp_insert_post( $add_new_post ); $return_data['post'] = 'true'; } if ( is_int( $new_post_id ) && $new_post_id > 0 ) { $return_data['new_post_html'] = DSAMM_Revision_Ajax_Action::dsamm_add_to_menu_html_own( $new_post_id ); $return_data['sucess'] = esc_html__( ' has been added successfully.', 'advance-menu-manager' ); } else { $return_data['error'] = esc_html__( 'Please try again later.', 'advance-menu-manager' ); } } else { $return_data['error'] = esc_html__( 'Please try again later.', 'advance-menu-manager' ); } echo wp_json_encode( $return_data ); exit; } /** * * AMM search texonomy term ajax action * * @version 1.0.2 * @author theDotstore */ public static function dsamm_my_action_for_amm_taxonomy_search() { check_ajax_referer( 'dsamm_ajax_value_nonce', 'security' ); $texo = filter_input( INPUT_POST, 'texo', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $search_text = filter_input( INPUT_POST, 'search_text', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $db_fields = false; if ( is_taxonomy_hierarchical( $texo ) ) { $db_fields = array( 'parent' => 'parent', 'id' => 'term_id', ); } $walker = new DSAMM_Walker_Nav_Menu_Checklist($db_fields); $args = array( 'taxonomy' => array($texo), 'order' => 'ASC', 'orderby' => 'name', 'hide_empty' => false, 'fields' => 'all', 'name__like' => $search_text, ); $terms = get_terms( $args ); $args['walker'] = $walker; $t_html = walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $terms ), 0, (object) $args ); if ( !empty( $t_html ) ) { $sucess = true; } else { $t_html = '
  • ' . esc_html__( 'No Record found', 'advance-menu-manager' ) . '
  • '; $sucess = false; } $return_data = array(); $return_data['html'] = $t_html; $return_data['sucess'] = $sucess; echo wp_json_encode( $return_data ); exit; } /** * * AMM edit menu fornt end ajax action * * @version 1.0.2 * @author theDotstore */ public static function dsamm_popup_menu_item_edit_frontend() { check_ajax_referer( 'dsamm_ajax_value_nonce', 'security' ); $return_data = array(); $action = filter_input( INPUT_POST, 'action', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_id = filter_input( INPUT_POST, 'post_id', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); if ( 'my_action_for_popup_menu_item_edit_front_end' == $action && !empty( $post_id ) ) { $gloable_all_author_array = array(); $gloable_all_template_array = array(); $gloable_all_category_array = array(); $item = get_post( $post_id ); //set all author $allUsers = get_users( 'orderby=ID&order=ASC' ); foreach ( $allUsers as $currentUser ) { if ( !in_array( 'subscriber', $currentUser->roles ) ) { $gloable_all_author_array[] = $currentUser; } } // set all template $get_templates_all = get_page_templates(); foreach ( $get_templates_all as $template_name => $template_filename ) { $gloable_all_template_array[$template_name] = $template_filename; } // set all category $all_category = get_categories( 'orderby=name&hide_empty=0' ); foreach ( $all_category as $cat_data ) { $gloable_all_category_array[$cat_data->cat_ID] = $cat_data->cat_name; } $html = ''; $cate_array = array(); $cate_id_array = array(); $current_post_category = ''; $html .= '
    Edit ' . $item->post_type . '
    Title
    Slug
    Author
    '; if ( 'page' == $item->post_type ) { $html .= '
    Template
    '; } else { if ( 'post' == $item->post_type ) { $category_detail = get_the_category( $item->ID ); if ( !empty( $category_detail ) && count( $category_detail ) > 0 ) { foreach ( $category_detail as $cd ) { $cate_array[] = $cd->cat_name; $cate_id_array[] = $cd->cat_ID; } } $html .= '
    Category
      '; foreach ( $gloable_all_category_array as $cate_id => $data_cat ) { $sleceted_id = ''; $sleceted_id = ( in_array( $data_cat, $cate_array ) ? "checked" : "" ); $html .= '
    • ' . $data_cat . '
    • '; } $html .= '
    '; } } $html .= '
    '; $html .= '
    Content

    '; $text_editor_buttons = array( "buttons" => 'strong,em,italic,b-quote,img,close,del,ins,ul,li,ol,code,spell,more,fullscreen', ); $tinymce_buttons = array( 'toolbar1' => 'bold,italic,strikethrough,bullist,numlist,blockquote,hr,alignleft,aligncenter,alignright,wp_more,spellchecker,dfw,', 'toolbar2' => "formatselect,underline,alignjustify,forecolor,removeformat,outdent,indent", 'toolbar3' => "", 'toolbar4' => "", ); $settings = array( 'wpautop' => true, 'media_buttons' => false, 'textarea_name' => 'amm_post_content_add', 'textarea_rows' => 20, 'tabindex' => '', 'tabfocus_elements' => ':prev,:next', 'editor_css' => 'amm-post-page-content', 'editor_class' => '', 'teeny' => false, 'dfw' => false, 'tinymce' => false, 'quicktags' => false, ); $wp_ediotr_id = 'amm_item_edit_content_123'; $html .= ''; $html .= '

    '; $html .= '
    '; if ( 'page' == $item->post_type ) { $html .= ''; } else { $html .= ''; } $html .= '
    '; $return_data['post_html'] = $html; $return_data['wp_editor_selector'] = $wp_ediotr_id; $return_data['sucess'] = esc_html__( 'Item has added successfully.', 'advance-menu-manager' ); } else { $return_data['error'] = esc_html__( 'Please try again later.', 'advance-menu-manager' ); } echo wp_json_encode( $return_data ); exit; } /** * * AMM edit menu forntend edit ajax action submited * * @version 1.0.2 * @author theDotstore */ public static function dsamm_main_popup_fontend_menu_item_edit_submit_action_own() { check_ajax_referer( 'dsamm_ajax_value_nonce', 'security' ); $return_data = array(); // Ensure the current user has access if ( !current_user_can( 'edit_posts' ) ) { $return_data['error'] = esc_html__( 'Unauthorized access.', 'advance-menu-manager' ); echo wp_json_encode( $return_data ); exit; } $action = filter_input( INPUT_POST, 'action', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_id = filter_input( INPUT_POST, 'post_id', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_title = filter_input( INPUT_POST, 'post_title', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_author = filter_input( INPUT_POST, 'post_author', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_slug = filter_input( INPUT_POST, 'post_slug', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_content = filter_input( INPUT_POST, 'post_content', FILTER_SANITIZE_SPECIAL_CHARS ); $post_content = html_entity_decode( $post_content ); $post_template = filter_input( INPUT_POST, 'post_template', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_category_old = filter_input( INPUT_POST, 'post_category_old', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_category_new = filter_input( INPUT_POST, 'post_category_new', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); if ( 'my_action_for_main_popup_fontend_menu_item_edit_submit' === $action && !empty( $post_id ) && !empty( $post_title ) ) { if ( !empty( $post_content ) ) { $update_my_post = array( 'ID' => $post_id, 'post_title' => $post_title, 'post_author' => $post_author, 'post_name' => $post_slug, 'post_content' => $post_content, ); } else { $update_my_post = array( 'ID' => $post_id, 'post_title' => $post_title, 'post_author' => $post_author, 'post_name' => $post_slug, ); } wp_update_post( $update_my_post ); if ( !empty( $_POST['post_category'] ) ) { $post_category_old = ( isset( $post_category_old ) ? $post_category_old : '' ); $old_cat_id_array = array_map( 'intval', explode( ',', $post_category_old ) ); $post_category_new = ( isset( $post_category_new ) ? $post_category_new : array() ); parse_str( $post_category_new, $new_cat_id_array ); $new_cat_id_array = ( !empty( $new_cat_id_array ) && isset( $new_cat_id_array['amp_item_category'] ) ? array_map( 'intval', $new_cat_id_array['amp_item_category'] ) : array() ); //update category wp_remove_object_terms( $post_id, $old_cat_id_array, 'category' ); wp_set_object_terms( $post_id, $new_cat_id_array, 'category' ); } else { if ( !empty( $post_template ) ) { update_post_meta( $post_id, '_wp_page_template', $post_template ); } } $return_data['sucess'] = "" . $post_title . "" . esc_html__( ' has been updated successfully.', 'advance-menu-manager' ); } else { $return_data['error'] = esc_html__( 'Please try again later.', 'advance-menu-manager' ); } echo wp_json_encode( $return_data ); exit; } /** * * New item menu html * * @version 1.0.2 * @author theDotstore */ public static function dsamm_add_to_menu_html_own( $post_ID = null ) { $output = ''; if ( !empty( $post_ID ) ) { global $_nav_menu_placeholder, $nav_menu_selected_id; $gloable_all_author_array = array(); $gloable_all_template_array = array(); $gloable_all_category_array = array(); //set all author globaly $allUsers = get_users( 'orderby=ID&order=ASC' ); foreach ( $allUsers as $currentUser ) { if ( !in_array( 'subscriber', $currentUser->roles ) ) { $gloable_all_author_array[] = $currentUser; } } // set all template globaly $get_templates_all = get_page_templates(); foreach ( $get_templates_all as $template_name => $template_filename ) { $gloable_all_template_array[$template_name] = $template_filename; } // set all category by globaly $all_category = get_categories( 'orderby=name&hide_empty=0' ); foreach ( $all_category as $cat_data ) { $gloable_all_category_array[$cat_data->cat_ID] = $cat_data->cat_name; } $cate_array = array(); $cate_id_array = array(); $current_post_category = ''; $item = get_post( $post_ID ); $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ? intval( $_nav_menu_placeholder ) - 1 : $item->ID ); //phpcs:ignore $possible_object_id = ( isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->ID : $_nav_menu_placeholder ); $possible_db_id = ( !empty( $item->ID ) && 0 < $possible_object_id ? (int) $item->ID : 0 ); $output .= '
  • '; $output .= ''; $output .= ''; $output .= ' '; // Menu item hidden fields $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $item_class = ( !empty( $item->classes ) ? implode( ' ', $item->classes ) : '' ); $output .= ''; $output .= ''; $output .= $item->ID . ''; $output .= ' '; $output .= ( strlen( esc_html( $item->post_title ) ) > 35 ? substr( esc_html( $item->post_title ), 0, 35 ) . '...' : esc_html( $item->post_title ) ); $output .= ' '; // display page/post custom post type menu item. // display page/post custom post type menu item. $output .= ''; $output .= ( strlen( $item->post_name ) > 20 ? substr( $item->post_name, 0, 20 ) . '...' : $item->post_name ); $output .= ''; $post_author_name = get_the_author_meta( 'display_name', $item->post_author ); $output .= '' . $post_author_name . ''; if ( 'page' == $item->post_type ) { $output .= ''; $tamplate_name = get_post_meta( $item->ID, '_wp_page_template', true ); if ( 'default' == $tamplate_name || empty( $tamplate_name ) ) { $output .= 'default'; } else { $template_name_key = array_search( $tamplate_name, $gloable_all_template_array ); if ( !empty( $template_name_key ) ) { $tamplate_name = $template_name_key; } else { $tamplate_name = 'default'; } $output .= $tamplate_name; } $output .= ''; } else { $category_detail = get_the_category( $item->ID ); $output .= ''; if ( !empty( $category_detail ) && count( $category_detail ) > 0 ) { foreach ( $category_detail as $cd ) { $cate_array[] = $cd->cat_name; $cate_id_array[] = $cd->cat_ID; } $current_post_category = implode( ',', $cate_array ); $output .= $current_post_category; } else { $output .= '-'; } $output .= ''; } $output .= '' . get_the_date( '', $item->ID ) . ''; $output .= ''; $output .= '
  • '; } return $output; } /** * * Add new item filter in menu * * @version 1.0.2 * @author theDotstore */ public static function dsamm_add_new_menu_item_html_own() { $return_data = array(); $action = filter_input( INPUT_POST, 'action', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); if ( !empty( $action ) && 'my_action_for_add_new_menu_item_html' === $action ) { check_ajax_referer( 'dsamm_ajax_value_nonce', 'security' ); } $page_no = filter_input( INPUT_POST, 'page_no', FILTER_SANITIZE_NUMBER_INT ); $post_type = filter_input( INPUT_POST, 'post_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $amm_menu_query = filter_input( INPUT_POST, 'amm_menu_query', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); if ( 'my_action_for_add_new_menu_item_html' == $action && !empty( $page_no ) && !empty( $post_type ) ) { global $_nav_menu_placeholder, $nav_menu_selected_id; //post per page as post wise $post_per_page = get_option( 'amm_' . $post_type ); if ( empty( $post_per_page ) ) { $post_per_page = get_option( 'amm_post_perpage_default' ); } $page_html = ''; if ( empty( $amm_menu_query ) ) { $post_type_name = $post_type; $per_page = $post_per_page; $args = array( 'paged' => $page_no, 'order' => 'ASC', 'orderby' => 'title', 'posts_per_page' => $per_page, 'post_type' => $post_type_name, 'suppress_filters' => false, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, ); // @todo transient caching of these results with proper invalidation on updating of a post of this type $get_posts = new WP_Query(); $posts = $get_posts->query( $args ); if ( !$get_posts->post_count ) { $page_html .= '
  • ' . esc_html__( 'No Record found', 'advance-menu-manager' ) . '
  • '; } else { $db_fields = false; if ( is_post_type_hierarchical( $post_type_name ) ) { $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID', ); } //$walker = new Walker_Nav_Menu_Checklist( $db_fields ); $walker = new DSAMM_Walker_Nav_Menu_Checklist($db_fields); $args['walker'] = $walker; /* * If we're dealing with pages, let's put a checkbox for the front * page at the top of the list. */ if ( 'page' == $post_type_name ) { $front_page = ( 'page' == get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0 ); if ( !empty( $front_page ) ) { $front_page_obj = get_post( $front_page ); $front_page_obj->front_or_home = true; array_unshift( $posts, $front_page_obj ); } else { if ( $page_no <= 1 ) { $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ? intval( $_nav_menu_placeholder ) - 1 : -1 ); //phpcs:ignore } } } $post_type = get_post_type_object( $post_type_name ); $archive_link = get_post_type_archive_link( $post_type_name ); if ( $post_type->has_archive ) { $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ? intval( $_nav_menu_placeholder ) - 1 : -1 ); //phpcs:ignore array_unshift( $posts, (object) array( 'ID' => 0, 'object_id' => $_nav_menu_placeholder, 'object' => $post_type_name, 'post_content' => '', 'post_excerpt' => '', 'post_title' => $post_type->labels->archives, 'post_type' => 'nav_menu_item', 'type' => 'post_type_archive', 'url' => get_post_type_archive_link( $post_type_name ), ) ); } /** * Filter the posts displayed in the 'View All' tab of the current * post type's menu items meta box. * * The dynamic portion of the hook name, `$post_type_name`, refers * to the slug of the current post type. * * @since 3.2.0 * * @see WP_Query::query() * * @param array $posts The posts for the current post type. * @param array $args An array of WP_Query arguments. * @param object $post_type The current post type object for this menu item meta box. */ $posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type ); $checkbox_items = walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $posts ), 0, (object) $args ); $page_html .= $checkbox_items; } } else { //amm_menu_query * @param string $taxonomy The taxonomy object. global $nav_menu_selected_id; $taxonomy_name = $post_type; $per_page = $post_per_page; $pagenum = ( isset( $_REQUEST['page_no'] ) ? absint( $_REQUEST['page_no'] ) : 1 ); $offset = ( 0 < $pagenum ? $per_page * ($pagenum - 1) : 0 ); $args = array( 'taxonomy' => $taxonomy_name, 'child_of' => 0, 'exclude' => '', 'hide_empty' => false, 'hierarchical' => 1, 'include' => '', 'number' => $per_page, 'offset' => $offset, 'order' => 'ASC', 'orderby' => 'name', 'pad_counts' => false, ); $terms = get_terms( $args ); if ( !$terms || is_wp_error( $terms ) ) { $page_html .= '
  • ' . esc_html__( 'No Record found', 'advance-menu-manager' ) . '
  • '; return; } $num_pages = ceil( wp_count_terms( $taxonomy_name, array_merge( $args, array( 'number' => '', 'offset' => '', ) ) ) / $per_page ); $total_page_count = wp_count_terms( $taxonomy_name, array_merge( $args, array( 'number' => '', 'offset' => '', ) ) ); $post_type_name = $taxonomy_name; $db_fields = false; if ( is_taxonomy_hierarchical( $taxonomy_name ) ) { $db_fields = array( 'parent' => 'parent', 'id' => 'term_id', ); } $walker = new DSAMM_Walker_Nav_Menu_Checklist($db_fields); $args['walker'] = $walker; $page_html .= walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $terms ), 0, (object) $args ); } $return_data['sucess'] = $page_html; } else { $return_data['error'] = esc_html__( 'Please try again later.', 'advance-menu-manager' ); } echo wp_json_encode( $return_data ); exit; } /** * * Add new item filter in menu * * @version 1.0.2 * @author theDotstore */ public static function dsamm_add_new_menu_item_html_filter_own() { check_ajax_referer( 'dsamm_ajax_value_nonce', 'security' ); $return_data = array(); $action = filter_input( INPUT_POST, 'action', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $post_type = filter_input( INPUT_POST, 'post_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $page_no = filter_input( INPUT_POST, 'page_no', FILTER_SANITIZE_NUMBER_INT ); $filter_author = filter_input( INPUT_POST, 'filter_author', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $filter_template = filter_input( INPUT_POST, 'filter_template', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $filter_category = filter_input( INPUT_POST, 'filter_category', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $filter_textbox = filter_input( INPUT_POST, 'filter_textbox', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $filter_menu_item = filter_input( INPUT_POST, 'filter_menu_item', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $amm_menu_query = filter_input( INPUT_POST, 'amm_menu_query', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); if ( 'my_action_for_add_new_menu_item_html_filter' == $action && !empty( $page_no ) && !empty( $post_type ) ) { global $_nav_menu_placeholder, $nav_menu_selected_id; $total_page_count = 0; $page_html = ''; $post_per_page = get_option( 'amm_' . $post_type ); if ( empty( $post_per_page ) ) { $post_per_page = get_option( 'amm_post_perpage_default' ); } if ( empty( $amm_menu_query ) ) { $post_type_name = $post_type; $per_page = $post_per_page; $args = array( 'paged' => $page_no, 'order' => 'ASC', 'orderby' => 'title', 'posts_per_page' => $per_page, 'post_type' => $post_type_name, 'suppress_filters' => false, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'post_status' => 'publish', ); if ( !empty( $filter_author ) && 'all' != $filter_author ) { $args['author'] = $filter_author; } if ( 'page' == $post_type_name ) { if ( !empty( $filter_template ) && 'all' != $filter_template ) { // phpcs:disabled $args['meta_query'] = array(array( 'key' => '_wp_page_template', 'value' => $filter_template, 'compare' => '=', )); // phpcs:enabled } } else { if ( !empty( $filter_category ) && 'all' != $filter_category ) { $args['category_name'] = $filter_category; } } if ( !empty( $filter_textbox ) ) { $args['s'] = $filter_textbox; } if ( $filter_menu_item == 'on' ) { $curent_menu_id = array(); $recently_edited = absint( get_user_option( 'nav_menu_recently_edited', get_current_user_id() ) ); $menu_items = wp_get_nav_menu_items( $recently_edited ); for ($amm = 0; $amm < count( $menu_items ); $amm++) { $curent_menu_id[] = $menu_items[$amm]->object_id; } $args['post__not_in'] = $curent_menu_id; } $removed_args = array( 'action', 'customlink-tab', 'edit-menu-item', 'menu-item', 'page-tab', '_wpnonce' ); // @todo transient caching of these results with proper invalidation on updating of a post of this type $get_posts = new WP_Query(); $posts = $get_posts->query( $args ); $get_posts_for_count = new WP_Query($args); $total_page_count = $get_posts_for_count->found_posts; if ( !$get_posts->post_count ) { $page_html .= '
  • ' . esc_html__( 'No Record found', 'advance-menu-manager' ) . '
  • '; } else { $db_fields = false; if ( is_post_type_hierarchical( $post_type_name ) ) { $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID', ); } //$walker = new Walker_Nav_Menu_Checklist( $db_fields ); $walker = new DSAMM_Walker_Nav_Menu_Checklist($db_fields); $args['walker'] = $walker; /* * If we're dealing with pages, let's put a checkbox for the front * page at the top of the list. */ if ( 'page' == $post_type_name ) { $front_page = ( 'page' == get_option( 'show_on_front' ) ? (int) get_option( 'page_on_front' ) : 0 ); if ( !empty( $front_page ) ) { $front_page_obj = get_post( $front_page ); $front_page_obj->front_or_home = true; array_unshift( $posts, $front_page_obj ); } else { $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ? intval( $_nav_menu_placeholder ) - 1 : -1 ); //phpcs:ignore } } $post_type = get_post_type_object( $post_type_name ); $archive_link = get_post_type_archive_link( $post_type_name ); if ( $post_type->has_archive ) { $_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ? intval( $_nav_menu_placeholder ) - 1 : -1 ); //phpcs:ignore array_unshift( $posts, (object) array( 'ID' => 0, 'object_id' => $_nav_menu_placeholder, 'object' => $post_type_name, 'post_content' => '', 'post_excerpt' => '', 'post_title' => $post_type->labels->archives, 'post_type' => 'nav_menu_item', 'type' => 'post_type_archive', 'url' => get_post_type_archive_link( $post_type_name ), ) ); } $posts = apply_filters( "nav_menu_items_{$post_type_name}", $posts, $args, $post_type ); $checkbox_items = walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $posts ), 0, (object) $args ); $page_html .= $checkbox_items; } } else { $taxonomy_name = $post_type; $per_page = $post_per_page; $pagenum = ( isset( $_REQUEST['page_no'] ) ? absint( $_REQUEST['page_no'] ) : 1 ); $offset = ( 0 < $pagenum ? $per_page * ($pagenum - 1) : 0 ); $term_args = array( 'taxonomy' => $taxonomy_name, 'hide_empty' => false, 'number' => $per_page, 'offset' => $offset, 'order' => 'ASC', 'orderby' => 'name', ); if ( !empty( $filter_textbox ) ) { $term_args['name__like'] = $filter_textbox; } if ( 'on' === $filter_menu_item ) { $curent_menu_id = array(); $recently_edited = absint( get_user_option( 'nav_menu_recently_edited', get_current_user_id() ) ); $menu_items = wp_get_nav_menu_items( $recently_edited ); if ( !empty( $menu_items ) ) { for ($amm = 0; $amm < count( $menu_items ); $amm++) { if ( $taxonomy_name === $menu_items[$amm]->object ) { $curent_menu_id[] = (int) $menu_items[$amm]->object_id; } } } if ( !empty( $curent_menu_id ) ) { $term_args['exclude'] = $curent_menu_id; } } $terms = get_terms( $term_args ); if ( !$terms || is_wp_error( $terms ) ) { $page_html .= '
  • ' . esc_html__( 'No Record found', 'advance-menu-manager' ) . '
  • '; } else { $count_args = array( 'taxonomy' => $taxonomy_name, 'hide_empty' => false, ); if ( !empty( $filter_textbox ) ) { $count_args['name__like'] = $filter_textbox; } if ( !empty( $term_args['exclude'] ) ) { $count_args['exclude'] = $term_args['exclude']; } $total_page_count = wp_count_terms( $taxonomy_name, $count_args ); if ( is_wp_error( $total_page_count ) ) { $total_page_count = count( $terms ); } $post_type_name = $taxonomy_name; $db_fields = false; if ( is_taxonomy_hierarchical( $taxonomy_name ) ) { $db_fields = array( 'parent' => 'parent', 'id' => 'term_id', ); } $walker = new DSAMM_Walker_Nav_Menu_Checklist($db_fields); $args = array(); $args['walker'] = $walker; $page_html .= walk_nav_menu_tree( array_map( 'wp_setup_nav_menu_item', $terms ), 0, (object) $args ); } } $return_data['sucess'] = $page_html; $return_data['total_page'] = $total_page_count; } else { $return_data['error'] = esc_html__( 'Please try again later.', 'advance-menu-manager' ); } echo wp_json_encode( $return_data ); exit; } /** * Pagination post per page feature * * @version 1.0.2 * @author theDotstore */ public static function dsamm_add_pagination_post_per_page_limit_method() { check_ajax_referer( 'dsamm_ajax_value_nonce', 'security' ); $return_data = array(); // Ensure the current user has the appropriate capability if ( !current_user_can( 'manage_options' ) ) { $return_data['error'] = esc_html__( 'Unauthorized access.', 'advance-menu-manager' ); echo wp_json_encode( $return_data ); exit; } $action = filter_input( INPUT_POST, 'action', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $amm_option_key = filter_input( INPUT_POST, 'amm_option_key', FILTER_SANITIZE_FULL_SPECIAL_CHARS ); $page_per_post = filter_input( INPUT_POST, 'page_per_post', FILTER_SANITIZE_NUMBER_INT ); // Enforce a specific prefix for option keys $option_prefix = 'amm_'; if ( 'my_action_for_add_pagination_limit' === $action && !empty( $amm_option_key ) ) { if ( strpos( $amm_option_key, $option_prefix ) === 0 ) { // Option key starts with the allowed prefix update_option( $amm_option_key, $page_per_post ); $return_data['sucess'] = esc_html__( 'Settings updated successfully.', 'advance-menu-manager' ); } else { // Invalid option key $return_data['error'] = esc_html__( 'Invalid option key.', 'advance-menu-manager' ); } } else { $return_data['error'] = esc_html__( 'Invalid action or missing parameters.', 'advance-menu-manager' ); } echo wp_json_encode( $return_data ); exit; } }