{$args['description']}

" : ""; $description .= ( isset( $args['after_description'] ) ) ? $args['after_description'] : ""; $description .= ( isset( $args['pro'] ) ) ? sprintf( "

%s

", ( self::pro_text( true ) ) ) : ""; $append_content = ( isset( $args['append_content'] ) ) ? "{$args['append_content']}" : ""; // Input attributes $input_atts = ( ! empty( $args['input_class'] ) ) ? "class='{$args['input_class']}'" : ''; $input_atts .= ( ! empty( $args['readonly'] ) ) ? " readonly='readonly'" : ''; $input_atts .= ( ! empty( $args['disabled'] ) ) ? " disabled='disabled'" : ''; $input_atts .= ( ! empty( $args['placeholder'] ) ) ? " placeholder='{$args['placeholder']}'" : ''; $input_atts .= ( ! empty( $args['extra_atts'] ) ) ? " {$args['extra_atts']}" : ''; // Display the field if the related class exists if ( ! empty( $args['class_exists'] ) ) { $related_classes = (array) $args['class_exists']; $related_classes_exist = 0; foreach ( $related_classes as $related_class ) { if ( class_exists( $related_class ) ) { $related_classes_exist = 1; break; } } // Do not display if the related class it not found if ( empty( $related_classes_exist ) ) { $field_type = $args['container_class'] = 'hidden'; } } // Check the container classes $container_class = ( isset( $args['container_class'] ) ) ? " class=\"{$args['container_class']} field-container\"" : " class=\"field-container\""; // Get the field value (if it is not set in $args) if ( ! empty( $args['value'] ) ) { $value = $args['value']; } else { // Extract the section and field name from $input_name preg_match( '/([^\[]+)(?:\[([^\[]+)\])(?:\[([^\[]+)\])?/', $input_name, $field_section_and_name ); if ( $field_section_and_name ) { $section_name = $field_section_and_name[1]; $field_name = $field_section_and_name[2]; if ( ! empty( $field_section_and_name[3] ) ) { $subsection_name = $field_section_and_name[3]; $value = ( isset( $permalink_manager_options[ $section_name ][ $field_name ][ $subsection_name ] ) ) ? $permalink_manager_options[ $section_name ][ $field_name ][ $subsection_name ] : $default; } else { $value = ( isset( $permalink_manager_options[ $section_name ][ $field_name ] ) ) ? $permalink_manager_options[ $section_name ][ $field_name ] : $default; } } else { $value = ( isset( $permalink_manager_options[ $input_name ] ) ) ? $permalink_manager_options[ $input_name ] : $default; } } switch ( $field_type ) { case 'checkbox' : $fields .= '
'; foreach ( $args['choices'] as $choice_value => $choice ) { $input_template = ""; if ( empty( $choice['label'] ) && is_array( $choice ) ) { if ( in_array( $choice_value, array( 'post_types', 'taxonomies' ) ) ) { $group_labels = array( 'post_types' => __( 'Post types', 'permalink-manager' ), 'taxonomies' => __( 'Taxonomies', 'permalink-manager' ) ); $fields .= sprintf( '

%s

', $group_labels[ $choice_value ] ); } foreach ( $choice as $sub_choice_value => $sub_choice ) { $label = ( ! empty( $sub_choice['label'] ) ) ? $sub_choice['label'] : $sub_choice; $atts = ( ! empty( $value[ $choice_value ] ) && in_array( $sub_choice_value, $value[ $choice_value ] ) ) ? "checked='checked'" : ""; $atts .= ( ! empty( $sub_choice['atts'] ) ) ? " {$sub_choice['atts']}" : ""; $fields .= sprintf( $input_template, $input_name, $input_atts, $sub_choice_value, "{$input_name}[{$choice_value}]", $atts, $label ); } } else { $label = ( ! empty( $choice['label'] ) ) ? $choice['label'] : $choice; $atts = ( is_array( $value ) && in_array( $choice_value, $value ) ) ? "checked='checked'" : ""; $atts .= ( ! empty( $choice['atts'] ) ) ? " {$choice['atts']}" : ""; $fields .= sprintf( $input_template, $input_name, $input_atts, $choice_value, $input_name, $atts, $label ); } } $fields .= '
'; // Add helper checkboxes for bulk actions if ( isset( $args['select_all'] ) || isset( $args['unselect_all'] ) ) { $select_all_label = ( ! empty( $args['select_all'] ) ) ? $args['select_all'] : __( 'Select all', 'permalink-manager' ); $unselect_all_label = ( ! empty( $args['unselect_all'] ) ) ? $args['unselect_all'] : __( 'Unselect all', 'permalink-manager' ); $fields .= "

"; $fields .= ( isset( $args['select_all'] ) ) ? "{$select_all_label} " : ""; $fields .= ( isset( $args['unselect_all'] ) ) ? "{$unselect_all_label}" : ""; $fields .= "

"; } break; case 'single_checkbox' : $fields .= '
'; if ( is_array( $value ) ) { $input_key = preg_replace( '/(.*)(?:\[([^\[]+)\])$/', '$2', $input_name ); $checked = ( ! empty( $value[ $input_key ] ) ) ? "checked='checked'" : ""; } else { $checked = ( $value == 1 ) ? "checked='checked'" : ""; } $checkbox_label = ( isset( $args['checkbox_label'] ) ) ? $args['checkbox_label'] : ''; $fields .= ""; $fields .= ""; $fields .= '
'; break; case 'radio' : $fields .= '
'; foreach ( $args['choices'] as $choice_value => $choice ) { $label = ( is_array( $choice ) ) ? $choice['label'] : $choice; $atts = ( $choice_value == $value ) ? "checked='checked'" : ""; $atts .= ( ! empty( $choice['atts'] ) ) ? " {$choice['atts']}" : ""; $fields .= ""; } $fields .= '
'; break; case 'select' : $fields .= ''; $fields .= "'; $fields .= ''; break; case 'textarea' : $fields .= sprintf( "", $input_atts, $input_name, $rows, esc_textarea( $value ) ); break; case 'pre' : $fields .= sprintf( "
%s
", $input_atts, esc_textarea( $value ) ); break; case 'info' : $fields .= sprintf( "
%s
", $input_atts, $value ); break; case 'clearfix' : return "
"; default : $input_type = ( in_array( $field_type, array( 'text', 'password', 'number', 'hidden' ) ) ) ? $field_type : 'text'; $fields .= sprintf( "<%s type='%s' %s value='%s' name='%s' />", 'input', $input_type, $input_atts, esc_attr( $value ), $input_name ); } // Get the final HTML output if ( isset( $args['container'] ) && $args['container'] == 'tools' ) { $html = ""; $html .= "

{$label}

"; $html .= "
{$fields}
"; $html .= $description; $html .= $append_content; $html .= ""; } else if ( isset( $args['container'] ) && $args['container'] == 'row' ) { $html = sprintf( "", esc_attr( preg_replace( '/(?:.*\[)(.*)(?:\].*)/', '$1', $input_name ) ), $input_name, $container_class ); $html .= sprintf( "", $input_name, $args['label'] ); $html .= sprintf( "
%s%s
", $fields, $description ); $html .= ""; $html .= ( $append_content ) ? "{$append_content}" : ""; } else if ( isset( $args['container'] ) && $args['container'] == 'screen-options' ) { $html = "
{$args['label']}"; $html .= "
{$fields}{$description}
"; $html .= ( $append_content ) ? "
{$append_content}
" : ""; $html .= "
"; } else { $html = $fields . $append_content; } return apply_filters( 'permalink_manager_field_output', $html ); } /** * Display hidden field to indicate posts or taxonomies admin sections * * @param string $type * * @return string */ static public function section_type_field( $type = 'post' ) { return self::generate_option_field( 'content_type', array( 'value' => $type, 'type' => 'hidden' ) ); } /** * Display the HTML output of form for provided fields array * * @param array $fields * @param string $container * @param array $button * @param string $sidebar * @param array $nonce * @param bool $wrap * @param string $form_class * * @return string */ static public function get_the_form( $fields = array(), $container = '', $button = array(), $sidebar = '', $nonce = array(), $wrap = false, $form_class = '' ) { // 1. Check if the content will be displayed in columns and button details switch ( $container ) { case 'columns-3' : $wrapper_class = 'columns-container'; $form_column_class = 'column column-2_3'; $sidebar_class = 'column column-1_3'; break; case 'tabs' : $wrapper_class = 'form settings-tabs'; $sidebar_class = $form_column_class = ''; break; // there will be more cases in the future ... default : $sidebar_class = 'sidebar'; $wrapper_class = $form_column_class = ''; } // 2. Process the array with button and nonce field settings $button_text = ( ! empty( $button['text'] ) ) ? $button['text'] : ''; $button_class = ( ! empty( $button['class'] ) ) ? $button['class'] : ''; $button_attributes = ( ! empty( $button['attributes'] ) ) ? $button['attributes'] : ''; $nonce_action = ( ! empty( $nonce['action'] ) ) ? $nonce['action'] : ''; $nonce_name = ( ! empty( $nonce['name'] ) ) ? $nonce['name'] : ''; $form_classes = ( ! empty( $form_class ) ) ? $form_class : ''; // 3. Now get the HTML output (start section row container) $html = ( $wrapper_class ) ? "
" : ''; // 4. Display settings tabs if ( $container == 'tabs' ) { // Get active section $active_tab = ( ! empty( $_POST['pm_active_tab'] ) ) ? sanitize_key( $_POST['pm_active_tab'] ) : key( array_slice( $fields, 0, 1, true ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing $html .= ""; } // 5. Display some notes if ( $sidebar_class && $sidebar ) { $html .= sprintf( "
", $sidebar_class ); $html .= "
"; $html .= $sidebar; $html .= "
"; $html .= "
"; } // 6. Start fields' section $html .= ( $form_column_class ) ? sprintf( "
", $form_column_class ) : ""; $html .= sprintf( "
", $form_classes ); $html .= ( $wrap ) ? "" : ""; // 7. Loop through all fields assigned to this section foreach ( $fields as $field_name => $field ) { $tab_name = ( isset( $field['fields'] ) ) ? $field_name : ''; $field_name = ( ! empty( $field['name'] ) ) ? $field['name'] : $field_name; // A. Display table row if ( isset( $field['container'] ) && $field['container'] == 'row' ) { $row_output = ""; // Loop through all fields assigned to this section if ( isset( $field['fields'] ) ) { foreach ( $field['fields'] as $section_field_id => $section_field ) { if ( is_string( $section_field ) ) { $row_output .= $section_field; } else { $section_field_name = ( ! empty( $section_field['name'] ) ) ? $section_field['name'] : "{$field_name}[$section_field_id]"; $section_field['container'] = 'row'; $row_output .= self::generate_option_field( $section_field_name, $section_field ); } } } else { $row_output .= self::generate_option_field( $field_name, $field ); } if ( isset( $field['section_name'] ) ) { if ( $container == 'tabs' ) { $is_active_tab = ( ! empty( $active_tab ) && $active_tab == $tab_name ) ? 'class="active-tab"' : ''; $html .= sprintf( "
", $tab_name, $tab_name, $is_active_tab ); } $html .= "

{$field['section_name']}

"; $html .= ( isset( $field['append_content'] ) ) ? $field['append_content'] : ""; $html .= ( isset( $field['description'] ) ) ? sprintf( "

%s

", $field['description'] ) : ""; $html .= sprintf( "
%s
", $field_name, $row_output ); $html .= ( $container == 'tabs' ) ? "
" : ""; } else { $html .= $row_output; } } // B. Display single field else { $html .= self::generate_option_field( $field_name, $field ); } } $html .= ( $wrap ) ? "" : ""; // 8. Add a hidden field with section name for settings page if ( $container == 'tabs' && ! empty( $active_tab ) ) { $html .= self::generate_option_field( 'pm_active_tab', array( 'value' => $active_tab, 'type' => 'hidden', 'readonly' => true ) ); } // 9. End the fields' section + add button & nonce fields if ( $nonce_action && $nonce_name ) { $html .= wp_nonce_field( $nonce_action, $nonce_name, true, false ); $html .= self::generate_option_field( 'pm_session_id', array( 'value' => uniqid(), 'type' => 'hidden' ) ); } $html .= ( $button_text ) ? get_submit_button( $button_text, $button_class, '', false, $button_attributes ) : ""; $html .= ''; $html .= ( $form_column_class ) ? "
" : ""; // 10. End the section row container $html .= ( $wrapper_class ) ? "" : ""; return $html; } /** * Get the plugin sections' HTML code * * @param array $sections * @param string $active_section * @param string $active_subsection * * @return string */ static public function get_plugin_sections_html( $sections, $active_section = '', $active_subsection = '' ) { global $permalink_manager_after_sections_html; $html = ""; return $html; } /** * Display the array or HTML table with updated slugs after one of the actions is triggered * * @param array $updated_array * @param bool $return_array * @param bool $display_full_table * @param bool $preview_mode * * @return array|string */ static function display_updated_slugs( $updated_array, $return_array = false, $display_full_table = true, $preview_mode = false ) { global $permalink_manager_before_sections_html, $adjust_id_url_filter_off; $updated_slugs_count = 0; $html = $main_content = $alert = ""; // Disable "Adjust IDs for multilingual functionality" in WPML to make sure that the correct URLs are displayed in the results table $adjust_id_url_filter_off = true; // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound if ( is_array( $updated_array ) ) { // Check if slugs should be displayed $first_slug = reset( $updated_array ); $show_slugs = ( ! empty( $_POST['mode'] ) && $_POST['mode'] == 'slugs' ) ? true : false; // phpcs:ignore WordPress.Security.NonceVerification.Missing $header_footer = ''; $header_footer .= sprintf( '%s', __( 'Title', 'permalink-manager' ) ); if ( $show_slugs ) { $header_footer .= ( isset( $first_slug['old_slug'] ) ) ? sprintf( '%s', __( 'Old Slug', 'permalink-manager' ) ) : ''; $header_footer .= ( isset( $first_slug['new_slug'] ) ) ? sprintf( '%s', __( 'New Slug', 'permalink-manager' ) ) : ''; } else { $header_footer .= sprintf( '%s', __( 'Old URI', 'permalink-manager' ) ); $header_footer .= sprintf( '%s', __( 'New URI', 'permalink-manager' ) ); } $header_footer .= ''; $screen_reader_button = sprintf( '', __( 'Show more details', 'permalink-manager' ) ); foreach ( $updated_array as $row ) { // Odd/even class $updated_slugs_count ++; $alternate_class = ( $updated_slugs_count % 2 == 1 ) ? ' class="alternate"' : ''; // Taxonomy if ( ! empty( $row['tax'] ) ) { $term_link = get_term_link( intval( $row['ID'] ), $row['tax'] ); $permalink = ( is_wp_error( $term_link ) ) ? "-" : $term_link; } else { $permalink = get_permalink( $row['ID'] ); } // Decode permalink $permalink = rawurldecode( rawurldecode( $permalink ) ); $main_content .= sprintf( '', $row['ID'], $alternate_class ); $main_content .= sprintf( '%s%s %s', __( 'Title', 'permalink-manager' ), sanitize_text_field( $row['item_title'] ), $permalink, $permalink, $screen_reader_button ); if ( $show_slugs ) { $main_content .= ( isset( $row['old_slug'] ) ) ? sprintf( '%s', __( 'Old Slug', 'permalink-manager' ), rawurldecode( $row['old_slug'] ) ) : ""; $main_content .= ( isset( $row['new_slug'] ) ) ? sprintf( '%s', __( 'New Slug', 'permalink-manager' ), rawurldecode( $row['new_slug'] ) ) : ""; } else { $main_content .= sprintf( '%s', __( 'Old URI', 'permalink-manager' ), rawurldecode( $row['old_uri'] ) ); $main_content .= sprintf( '%s', __( 'New URI', 'permalink-manager' ), rawurldecode( $row['new_uri'] ) ); } $main_content .= ''; } // Merge header, footer and content if ( $display_full_table ) { $html = sprintf( '

%s

', __( 'List of updated items', 'permalink-manager' ) ); $html .= ''; $html .= sprintf( '%s%s%s', $header_footer, $main_content, $header_footer ); } else { $html = $main_content; } $html .= '
'; } // 3. Display the alert if ( isset( $updated_slugs_count ) ) { if ( $updated_slugs_count > 0 && ! $preview_mode ) { // translators: %d is the number of items where custom permalinks were updated $alert_content = sprintf( _n( '%d item was updated!', '%d items were updated!', $updated_slugs_count, 'permalink-manager' ), $updated_slugs_count ) . ' '; // translators: %s is the anchor link to the updated items' table $alert_content .= sprintf( __( 'Click here to go to the list of processed items', 'permalink-manager' ), "href=\"#updated-list\"" ); $alert = self::get_alert_message( $alert_content, 'updated updated_slugs' ); } else { $alert_content = ( $preview_mode ) ? sprintf( '[%s] ', __( 'Preview mode', 'permalink-manager' ) ) : ''; $alert_content .= __( 'No items were processed!', 'permalink-manager' ); $alert = self::get_alert_message( $alert_content, 'error updated_slugs' ); } } if ( $return_array ) { return array( 'html' => $html, 'alert' => $alert ); } else { $permalink_manager_before_sections_html .= $alert; return $html; } } /** * Get the HTML output of URI Editor * * @param WP_Post|WP_Term $element * @param bool $gutenberg * * @return string */ public static function display_uri_box( $element, $gutenberg = false ) { global $permalink_manager_options; // Check the user capabilities if ( Permalink_Manager_Admin_Functions::current_user_can_edit_uris() === false ) { return ''; } if ( ! empty( $element->ID ) ) { $id = $element_id = $element->ID; $native_slug = $element->post_name; $auto_update_val = get_post_meta( $id, "auto_update_uri", true ); $is_draft = ( ! empty( $element->post_status ) && ( in_array( $element->post_status, array( 'draft', 'auto-draft' ) ) ) ) ? true : false; $is_draft_excluded = Permalink_Manager_Helper_Functions::is_draft_excluded( $element ); $is_front_page = Permalink_Manager_Helper_Functions::is_front_page( $id ); // Allow users force the URI Editor to appear for drafts and auto-drafts if ( $is_draft_excluded && $is_draft ) { $is_draft_excluded = apply_filters( 'permalink_manager_auto_draft_hide_editor', $is_draft_excluded, $element, $gutenberg ); } // Get URIs $uri = Permalink_Manager_URI_Functions_Post::get_post_uri( $id, true, $is_draft ); $default_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri( $id ); $native_uri = Permalink_Manager_URI_Functions_Post::get_default_post_uri( $id, true ); } else if ( class_exists( 'Permalink_Manager_URI_Functions_Tax' ) ) { $id = $element->term_id; $element_id = "tax-{$id}"; $native_slug = $element->slug; $auto_update_val = get_term_meta( $id, "auto_update_uri", true ); // Get URIs $uri = Permalink_Manager_URI_Functions_Tax::get_term_uri( $element->term_id, true ); $default_uri = Permalink_Manager_URI_Functions_Tax::get_default_term_uri( $element->term_id ); $native_uri = Permalink_Manager_URI_Functions_Tax::get_default_term_uri( $element->term_id, true ); } else { return ''; } // If the draft is excluded do not display the contents of URI Editor if ( ! empty( $is_draft_excluded ) ) { if ( ! empty( $element->post_status ) && $element->post_status == 'auto-draft' ) { $alert = __( 'Save your post to activate the permalink editor and make changes to the custom permalink.', 'permalink-manager' ); } else { /* translators: Link to settings page */ $alert = sprintf( __( 'The custom permalink cannot be edited due to the Permalink Manager settings ("Exclude drafts & pending posts") and the post status not allowing it.', 'permalink-manager' ), Permalink_Manager_Admin_Functions::get_admin_url( '§ion=settings#exclusion' ) ); } $html = ( ! $gutenberg ) ? "