diff --git a/modules/story-budget/story-budget.php b/modules/story-budget/story-budget.php index ee524097..43285cba 100644 --- a/modules/story-budget/story-budget.php +++ b/modules/story-budget/story-budget.php @@ -7,24 +7,27 @@ */ class EF_Story_Budget extends EF_Module { - var $taxonomy_used = 'category'; + public $taxonomy_used = 'category'; - var $module; + public $module; - var $num_columns = 0; + public $num_columns = 0; - var $max_num_columns; + public $max_num_columns; - var $no_matching_posts = true; + public $no_matching_posts = true; - var $terms = array(); + public $terms = array(); - var $user_filters; + public $user_filters; + // phpcs:ignore Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase const screen_id = 'dashboard_page_story-budget'; + // phpcs:ignore Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase const usermeta_key_prefix = 'ef_story_budget_'; + // phpcs:ignore Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase const default_num_columns = 1; private $term_columns; @@ -32,12 +35,13 @@ class EF_Story_Budget extends EF_Module { /** * Register the module with Edit Flow but don't do anything else */ - function __construct() { + public function __construct() { $this->module_url = $this->get_module_url( __FILE__ ); // Register the module with Edit Flow $args = array( 'title' => __( 'Story Budget', 'edit-flow' ), + // translators: %s is a link to the story budget page 'short_description' => sprintf( __( 'View the status of all your content at a glance.', 'edit-flow' ), admin_url( 'index.php?page=story-budget' ) ), 'extended_description' => __( 'Use the story budget to see how content on your site is progressing. Filter by specific categories or date ranges to see details about each post in progress.', 'edit-flow' ), 'module_url' => $this->module_url, @@ -50,17 +54,17 @@ function __construct() { 'autoload' => false, ); $this->module = EditFlow()->register_module( 'story_budget', $args ); - } /** * Initialize the rest of the stuff in the class if the module is active */ - function init() { + public function init() { $view_story_budget_cap = apply_filters( 'ef_view_story_budget_cap', 'ef_view_story_budget' ); - if ( !current_user_can( $view_story_budget_cap ) ) + if ( ! current_user_can( $view_story_budget_cap ) ) { return; + } $this->num_columns = $this->get_num_columns(); $this->max_num_columns = apply_filters( 'ef_story_budget_max_num_columns', 3 ); @@ -78,7 +82,6 @@ function init() { // Load necessary scripts and stylesheets add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'action_enqueue_admin_styles' ) ); - } /** @@ -86,15 +89,15 @@ function init() { * * @since 0.7 */ - function install() { + public function install() { $story_budget_roles = array( 'administrator' => array( 'ef_view_story_budget' ), - 'editor' => array( 'ef_view_story_budget' ), - 'author' => array( 'ef_view_story_budget' ), - 'contributor' => array( 'ef_view_story_budget' ) + 'editor' => array( 'ef_view_story_budget' ), + 'author' => array( 'ef_view_story_budget' ), + 'contributor' => array( 'ef_view_story_budget' ), ); - foreach( $story_budget_roles as $role => $caps ) { + foreach ( $story_budget_roles as $role => $caps ) { $this->add_caps_to_role( $role, $caps ); } } @@ -104,23 +107,23 @@ function install() { * * @since 0.7 */ - function upgrade( $previous_version ) { + public function upgrade( $previous_version ) { global $edit_flow; // Upgrade path to v0.7 - if ( version_compare( $previous_version, '0.7' , '<' ) ) { + if ( version_compare( $previous_version, '0.7', '<' ) ) { // Migrate whether the story budget was enabled or not and clean up old option - if ( $enabled = get_option( 'edit_flow_story_budget_enabled' ) ) + if ( $enabled = get_option( 'edit_flow_story_budget_enabled' ) ) { $enabled = 'on'; - else + } else { $enabled = 'off'; + } $edit_flow->update_module_option( $this->module->name, 'enabled', $enabled ); delete_option( 'edit_flow_story_budget_enabled' ); // Technically we've run this code before so we don't want to auto-install new data $edit_flow->update_module_option( $this->module->name, 'loaded_once', true ); } - } /** @@ -128,8 +131,8 @@ function upgrade( $previous_version ) { * * @uses add_submenu_page() */ - function action_admin_menu() { - add_submenu_page( 'index.php', __('Story Budget', 'edit-flow'), __('Story Budget', 'edit-flow'), apply_filters( 'ef_view_story_budget_cap', 'ef_view_story_budget' ), $this->module->slug, array( $this, 'story_budget') ); + public function action_admin_menu() { + add_submenu_page( 'index.php', __( 'Story Budget', 'edit-flow' ), __( 'Story Budget', 'edit-flow' ), apply_filters( 'ef_view_story_budget_cap', 'ef_view_story_budget' ), $this->module->slug, array( $this, 'story_budget' ) ); } /** @@ -137,11 +140,12 @@ function action_admin_menu() { * * @uses enqueue_admin_script() */ - function enqueue_admin_scripts() { + public function enqueue_admin_scripts() { global $current_screen; - if ( $current_screen->id != self::screen_id ) + if ( self::screen_id != $current_screen->id ) { return; + } $num_columns = $this->get_num_columns(); echo ''; @@ -153,11 +157,12 @@ function enqueue_admin_scripts() { /** * Enqueue a screen and print stylesheet for the story budget. */ - function action_enqueue_admin_styles() { + public function action_enqueue_admin_styles() { global $current_screen; - if ( $current_screen->id != self::screen_id ) + if ( self::screen_id != $current_screen->id ) { return; + } wp_enqueue_style( 'edit_flow-story_budget-styles', $this->module_url . 'lib/story-budget.css', false, EDIT_FLOW_VERSION, 'screen' ); wp_enqueue_style( 'edit_flow-story_budget-print-styles', $this->module_url . 'lib/story-budget-print.css', false, EDIT_FLOW_VERSION, 'print' ); @@ -169,7 +174,7 @@ function action_enqueue_admin_styles() { * * @since 0.7 */ - function register_term_columns() { + public function register_term_columns() { $term_columns = array( 'title' => __( 'Title', 'edit-flow' ), @@ -188,17 +193,18 @@ function register_term_columns() { * * @since 0.7 */ - function handle_form_date_range_change() { + public function handle_form_date_range_change() { if ( ! isset( $_POST['ef-story-budget-range-submit'], $_POST['ef-story-budget-number-days'], $_POST['ef-story-budget-start-date_hidden'] ) ) { return; } - if ( !wp_verify_nonce( $_POST['nonce'], 'change-date' ) ) - wp_die( $this->module->messages['nonce-failed'] ); + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'change-date' ) ) { + wp_die( esc_html( $this->module->messages['nonce-failed'] ) ); + } $current_user = wp_get_current_user(); - $new_filters = array ( + $new_filters = array( 'start_date' => $_POST['ef-story-budget-start-date_hidden'], 'number_days' => (int) $_POST['ef-story-budget-number-days'], ); @@ -245,7 +251,7 @@ public function update_user_filters_from_form_date_range_change( $current_user, /** * Get the number of columns to show on the story budget */ - function get_num_columns() { + public function get_num_columns() { if ( empty( $this->num_columns ) ) { $current_user = wp_get_current_user(); @@ -264,18 +270,18 @@ function get_num_columns() { * * @since 0.8.3 */ - function add_screen_options_panel() { - require_once( EDIT_FLOW_ROOT . '/common/php/' . 'screen-options.php' ); + public function add_screen_options_panel() { + require_once EDIT_FLOW_ROOT . '/common/php/screen-options.php'; add_screen_options_panel( self::usermeta_key_prefix . 'screen_columns', __( 'Screen Layout', 'edit-flow' ), array( $this, 'print_column_prefs' ), self::screen_id, array( $this, 'save_column_prefs' ), true ); } /** * Print column number preferences for screen options */ - function print_column_prefs() { + public function print_column_prefs() { $return_val = __( 'Number of Columns: ', 'edit-flow' ); for ( $i = 1; $i <= $this->max_num_columns; ++$i ) { - $return_val .= "\n"; + $return_val .= "\n"; } return $return_val; } @@ -283,7 +289,7 @@ function print_column_prefs() { /** * Save the current user's preference for number of columns. */ - function save_column_prefs( $posted_fields ) { + public function save_column_prefs( $posted_fields ) { $key = self::usermeta_key_prefix . 'screen_columns'; $this->num_columns = (int) $posted_fields[ $key ]; @@ -297,23 +303,23 @@ function save_column_prefs( $posted_fields ) { * ouput any messages, create the table navigation, then print the columns based on * get_num_columns(), which will in turn print the stories themselves. */ - function story_budget() { + public function story_budget() { // Update the current user's filters with the variables set in $_GET $this->user_filters = $this->update_user_filters(); - if ( !empty( $this->user_filters[$this->taxonomy_used] ) ) { + if ( ! empty( $this->user_filters[ $this->taxonomy_used ] ) ) { $terms = array(); - $terms[] = get_term( $this->user_filters[$this->taxonomy_used], $this->taxonomy_used ); + $terms[] = get_term( $this->user_filters[ $this->taxonomy_used ], $this->taxonomy_used ); } else { // Get all of the terms from the taxonomy, regardless whether there are published posts - $args = array( + $terms = get_terms( array( + 'taxonomy' => $this->taxonomy_used, 'orderby' => 'name', 'order' => 'asc', 'hide_empty' => 0, 'parent' => 0, - ); - $terms = get_terms( $this->taxonomy_used, $args ); + )); } $this->terms = apply_filters( 'ef_story_budget_filter_terms', $terms ); // allow for reordering or any other filtering of terms @@ -328,22 +334,22 @@ function story_budget() {
'; ?> @@ -355,9 +361,9 @@ function story_budget() { * * @since 0.7 */ - function story_budget_time_range() { + public function story_budget_time_range() { ?> -