Use new code style

This commit is contained in:
David Stone
2025-02-07 19:02:33 -07:00
parent 0181024ae1
commit 8433379d90
672 changed files with 37107 additions and 45249 deletions

View File

@ -85,14 +85,13 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
/*
* Sets current section for future reference.
*/
$this->current_section = $sections[$this->get_current_section()];
$this->current_section = $sections[ $this->get_current_section() ];
/*
* Process save, if necessary
*/
$this->process_save();
} // end page_loaded;
}
/**
* Handles saves, after verifying nonces and such. Should not be rewritten by child classes.
@ -104,8 +103,7 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
$saving_tag = sprintf('saving_%s', $this->get_current_section());
if (isset($_REQUEST[$saving_tag])) {
if (isset($_REQUEST[ $saving_tag ])) {
check_admin_referer($saving_tag, '_wpultimo_nonce');
$handler = isset($this->current_section['handler']) ? $this->current_section['handler'] : array($this, 'default_handler');
@ -114,10 +112,8 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
* Calls the saving function
*/
call_user_func($handler);
} // end if;
} // end process_save;
}
}
/**
* Returns the labels to be used on the admin page.
@ -136,8 +132,7 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
'save_button_label' => __('Save', 'wp-ultimo'),
'save_description' => '',
);
} // end get_labels;
}
/**
* Registers widgets to the edit page.
@ -154,14 +149,11 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
$screen = get_current_screen();
if (wu_get_isset($this->current_section, 'separator')) {
return;
} // end if;
}
add_meta_box('wp-ultimo-wizard-body', wu_get_isset($this->current_section, 'title', __('Section', 'wp-ultimo')), array($this, 'output_default_widget_body'), $screen->id, 'normal', null);
} // end register_widgets;
}
/**
* Outputs the markup for the default Save widget.
@ -181,8 +173,7 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
call_user_func($view);
echo '</div>';
} // end output_default_widget_body;
}
/**
* Returns the logo to be used on the wizard.
@ -193,8 +184,7 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
public function get_logo() {
return '';
} // end get_logo;
}
/**
* Displays the contents of the edit page.
@ -206,19 +196,21 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
/*
* Renders the base edit page layout, with the columns and everything else =)
*/
wu_get_template('base/wizard', array(
'screen' => get_current_screen(),
'page' => $this,
'logo' => $this->get_logo(),
'labels' => $this->get_labels(),
'sections' => $this->get_sections(),
'current_section' => $this->get_current_section(),
'classes' => 'wu-w-full wu-mx-auto sm:wu-w-11/12 xl:wu-w-8/12 wu-mt-8 sm:wu-max-w-screen-lg',
'clickable_navigation' => $this->clickable_navigation,
'form_id' => $this->form_id,
));
} // end output;
wu_get_template(
'base/wizard',
array(
'screen' => get_current_screen(),
'page' => $this,
'logo' => $this->get_logo(),
'labels' => $this->get_labels(),
'sections' => $this->get_sections(),
'current_section' => $this->get_current_section(),
'classes' => 'wu-w-full wu-mx-auto sm:wu-w-11/12 xl:wu-w-8/12 wu-mt-8 sm:wu-max-w-screen-lg',
'clickable_navigation' => $this->clickable_navigation,
'form_id' => $this->form_id,
)
);
}
/**
* Returns the first section of the signup process
@ -230,16 +222,11 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
$keys = array_keys($this->get_sections());
if (isset($keys[1])) {
return $keys[1];
} else {
return false;
} // end if;
} // end get_first_section;
}
}
/**
* Get the current section
@ -252,11 +239,10 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
$sections = array_filter($sections, fn($item) => wu_get_isset($item, 'addon') === false);
$current_section = isset($_GET[$this->section_slug]) ? sanitize_key($_GET[$this->section_slug]) : current(array_keys($sections));
$current_section = isset($_GET[ $this->section_slug ]) ? sanitize_key($_GET[ $this->section_slug ]) : current(array_keys($sections));
return $current_section;
} // end get_current_section;
}
/**
* Returns the page link for the current section.
@ -269,8 +255,7 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
public function get_section_link($section) {
return add_query_arg($this->section_slug, $section);
} // end get_section_link;
}
/**
* Returns the link to the next section on the wizard.
@ -286,9 +271,8 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
$keys = array_keys($sections);
return add_query_arg($this->section_slug, $keys[array_search($current_section, array_keys($sections), true) + 1]);
} // end get_next_section_link;
return add_query_arg($this->section_slug, $keys[ array_search($current_section, array_keys($sections), true) + 1 ]);
}
/**
* Returns the link to the previous section on the wizard.
@ -304,9 +288,8 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
$keys = array_keys($sections);
return add_query_arg($this->section_slug, $keys[array_search($current_section, array_keys($sections), true) - 1]);
} // end get_prev_section_link;
return add_query_arg($this->section_slug, $keys[ array_search($current_section, array_keys($sections), true) - 1 ]);
}
/**
* Default handler for step submission. Simply redirects to the next step.
@ -319,8 +302,7 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
wp_redirect($this->get_next_section_link());
exit;
} // end default_handler;
}
/**
* Default method for views.
@ -330,49 +312,57 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
*/
public function default_view() {
$section = wp_parse_args($this->current_section, array(
'title' => '',
'description' => '',
'content' => '',
'fields' => array(),
'next_label' => __('Continue &rarr;', 'wp-ultimo'),
'back_label' => __('&larr; Go Back', 'wp-ultimo'),
'skip_label' => __('Skip this Step', 'wp-ultimo'),
'back' => false,
'skip' => false,
'next' => true,
));
$section = wp_parse_args(
$this->current_section,
array(
'title' => '',
'description' => '',
'content' => '',
'fields' => array(),
'next_label' => __('Continue &rarr;', 'wp-ultimo'),
'back_label' => __('&larr; Go Back', 'wp-ultimo'),
'skip_label' => __('Skip this Step', 'wp-ultimo'),
'back' => false,
'skip' => false,
'next' => true,
)
);
/*
* Check if the section has fields
*/
if (!empty($section['fields'])) {
if ( ! empty($section['fields'])) {
if (is_callable($section['fields'])) {
$section['fields'] = call_user_func($section['fields']);
}
} // end if;
$form = new \WP_Ultimo\UI\Form($this->get_current_section(), $section['fields'], array(
'views' => 'admin-pages/fields',
'classes' => 'wu-widget-list wu-striped wu-m-0 wu-mt-2 wu--mb-6 wu--mx-6',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-px-6 wu-py-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
));
$form = new \WP_Ultimo\UI\Form(
$this->get_current_section(),
$section['fields'],
array(
'views' => 'admin-pages/fields',
'classes' => 'wu-widget-list wu-striped wu-m-0 wu-mt-2 wu--mb-6 wu--mx-6',
'field_wrapper_classes' => 'wu-w-full wu-box-border wu-items-center wu-flex wu-justify-between wu-px-6 wu-py-4 wu-m-0 wu-border-t wu-border-l-0 wu-border-r-0 wu-border-b-0 wu-border-gray-300 wu-border-solid',
)
);
ob_start();
$form->render();
$section['content'] = ob_get_clean();
}
} // end if;
wu_get_template('wizards/setup/default', array_merge($section, array(
'page' => $this,
)));
} // end default_view;
wu_get_template(
'wizards/setup/default',
array_merge(
$section,
array(
'page' => $this,
)
)
);
}
/**
* Renders the default submit box with action buttons at the bottom of the wizard.
@ -382,13 +372,15 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
*/
public function render_submit_box() {
wu_get_template('base/wizard/submit-box', array(
'screen' => get_current_screen(),
'page' => $this,
'labels' => $this->get_labels(),
));
} // end render_submit_box;
wu_get_template(
'base/wizard/submit-box',
array(
'screen' => get_current_screen(),
'page' => $this,
'labels' => $this->get_labels(),
)
);
}
/**
* Wizard classes should implement a method that returns an array of sections and subsections.
@ -396,6 +388,5 @@ abstract class Wizard_Admin_Page extends Base_Admin_Page {
* @since 2.0.0
* @return array
*/
abstract public function get_sections(); // end get_sections;
} // end class Wizard_Admin_Page;
abstract public function get_sections();
}