diff --git a/includes/admin-functions.php b/includes/admin-functions.php
index afc8ae3..7886aea 100755
--- a/includes/admin-functions.php
+++ b/includes/admin-functions.php
@@ -163,8 +163,7 @@ function wpfc_sermon_order( $vars ) {
break;
case 'preached':
$vars = array_merge( $vars, array(
- 'meta_key' => 'sermon_date',
- 'orderby' => 'meta_value'
+ 'orderby' => 'date'
) );
break;
}
@@ -234,7 +233,7 @@ function wpfc_sermon_columns( $column ) {
$data = wpfc_entry_views_get( array( 'post_id' => $post->ID ) );
break;
case "preached":
- $data = wpfc_sermon_date_filter( 0, '', $post );
+ $data = get_the_date();
break;
case "passage":
$data = get_post_meta( $post->ID, 'bible_passage', true );
diff --git a/includes/fix-dates.php b/includes/fix-dates.php
deleted file mode 100644
index 5399741..0000000
--- a/includes/fix-dates.php
+++ /dev/null
@@ -1,323 +0,0 @@
-attachWP();
- $this->defineActions();
-
- if ( ! boolval( get_option( 'wpfc_sm_dates_all_fixed', '0' ) ) ) {
- add_action( 'admin_notices', array( self::getInstance(), 'render_warning' ) );
- }
-
- return true;
- }
-
- /**
- * Add actions/filters to WP
- *
- * @return void
- */
- public function attachWP() {
- add_action( 'wpfc_fix_dates', array( self::getInstance(), 'fix' ) );
- }
-
- /**
- * Get new instance self or current one if exists
- *
- * @return WPFC_Fix_Dates
- */
- public static function getInstance() {
- if ( null === self::$instance ) {
- self::$instance = new self;
- }
-
- return self::$instance;
- }
-
- /**
- * Will define actions and corresponding integers:
- * SM_DATES_NONE = 0
- * SM_DATES_CHECK = 1
- * SM_DATES_FIX = 2
- * SM_DATES_REVERT = 9
- *
- * @return bool True on success
- * @throws ErrorException Throws if constants are already defined and have a different value. This should never
- * happen, but better be safe than sorry.
- */
- public function defineActions() {
- $actions = array(
- 'SM_DATES_NONE' => 0,
- 'SM_DATES_CHECK' => 1,
- 'SM_DATES_FIX' => 2,
- 'SM_DATES_REVERT' => 9,
- );
-
- foreach ( $actions as $action => $value ) {
- if ( defined( $action ) ) {
- if ( constant( $action ) !== $value ) {
- throw new ErrorException( 'Please try to deactivate all plugins except Sermon Manager and try again.', 1 );
- }
- } else {
- define( $action, $value );
- }
- }
-
- return true;
- }
-
- /**
- * Gets last action that has been executed
- *
- * @return int|null Action int if success, null on failure
- * @see defineActions()
- */
- public function getLastAction() {
- $action = get_option( 'wpfc_sm_dates_last_action', SM_DATES_NONE );
-
- if ( $action !== SM_DATES_NONE ) {
- if ( ! is_numeric( $action ) ) {
- return $this->getAction( $action );
- }
- }
-
- return $action;
- }
-
- /**
- * Converts textual action to int
- *
- * @param string $action The action
- *
- * @return int|null Action int if success, null on failure
- * @see defineActions()
- */
- public function getAction( $action ) {
- if ( is_numeric( $action ) ) {
- return intval( $action );
- }
-
- switch ( $action ) {
- case "check":
- return SM_DATES_CHECK;
- case "fix":
- return SM_DATES_FIX;
- case "revert";
- return SM_DATES_REVERT;
- }
-
- return SM_DATES_NONE;
- }
-
- /**
- * Function used to display a message in WP admin area.
- *
- * @return void
- */
- public function render_warning() {
- ?>
-
-
Important! Sermon Manager needs to check dates of old sermons.
- Click
- here if you want to do it now.
-
- getCurrentAction();
- $old_dates = $this->getDatesStats();
-
- if ( $action === SM_DATES_NONE && $old_dates['total'] < 0 ) {
- ?>
- Click on "Check dates for errors" to begin...
-
- Checking for errors...
- getAllDates( true );
- $dates_stats = $this->getDatesStats();
- if ( $dates_stats['total'] < 1 ) {
- update_option( 'wpfc_sm_dates_total', count( $dates ) );
- update_option( 'wpfc_sm_dates_remaining', count( $dates ) );
- update_option( 'wpfc_sm_dates_fixed', 0 );
- update_option( 'wpfc_sm_dates_checked', 1 );
- update_option( 'wpfc_sm_dates_last_action', SM_DATES_CHECK );
- update_option( 'wpfc_sm_dates_old', serialize( $dates ) );
-
- if ( count( $dates ) === 0 ) {
- update_option( 'wpfc_sm_dates_all_fixed', 1 );
- }
- }
- ?>
-
Done.
-
- ';
- flush();
-
- $dates = unserialize( get_option( 'wpfc_sm_dates_old', serialize( array() ) ) );
- $fixed = 0;
-
- if ( ! empty( $dates ) ) {
- echo 'Fixing dates...
';
- flush();
- foreach ( $dates as $date ) {
- // for backup
- add_post_meta( $date['post_id'], 'sermon_date_old', $date['date'] );
- // update the date
- update_post_meta( $date['post_id'], 'sermon_date', strtotime( $date['date'] ) );
- // add it to fixed dates
- $fixed ++;
- }
-
- update_option( 'wpfc_sm_dates_fixed', $fixed );
- update_option( 'wpfc_sm_dates_remaining', intval( get_option( 'wpfc_sm_dates_total', true ) ) - $fixed );
- }
-
- update_option( 'wpfc_sm_dates_all_fixed', 1 );
-
- echo 'Date fixing completed.
';
- flush();
-
- echo '';
- echo wpfc_console_zsh( '', false );
- }
- }
-
- /**
- * Gets current action that is being executed
- *
- * @return int|null Action int if success, null on failure
- * @see defineActions()
- */
- public function getCurrentAction() {
- $action = SM_DATES_NONE;
-
- if ( isset( $_GET['fix_dates'] ) && $_GET['fix_dates'] !== '' ) {
- $action = $_GET['fix_dates'];
- } else if ( isset( $_POST['fix_dates'] ) && $_POST['fix_dates'] !== '' ) {
- $action = $_POST['fix_dates'];
- }
-
- return $this->getAction( $action );
- }
-
- /**
- * Gets some statistics about dates scan
- *
- * @return array[] Details about old dates.
- * @type int $old_dates ['total'] = Total old dates, the number on the first scan
- * @type int $old_dates ['fixed'] = Number of fixed dates
- * @type int $old_dates ['remaining'] = How many are left to do.
- */
- public function getDatesStats() {
- $option_names = array(
- 'total' => 'wpfc_sm_dates_total',
- 'fixed' => 'wpfc_sm_dates_fixed',
- 'remaining' => 'wpfc_sm_dates_remaining',
- );
-
- $stats = array();
- foreach ( $option_names as $name => $option_name ) {
- $stats[ $name ] = get_option( $option_name, - 1 );
- }
-
- return $stats;
- }
-
- /**
- * Get all sermon dates from post meta
- *
- * @param bool $filter_old True to get only old dates, false for all (default false)
- *
- * @return array Array of post meta IDs, dates and sermon dates
- */
- public function getAllDates( $filter_old = false ) {
- global $wpdb;
- $wp_query = new WP_Query( array(
- 'post_type' => 'wpfc_sermon',
- 'posts_per_page' => - 1,
- 'post_status' => 'any'
- ) );
- $posts_meta = array();
-
- $sermons = $wp_query->posts;
-
- foreach ( $sermons as $sermon ) {
- // get post meta directly from DB. The reason for not using get_post_meta() is that we need meta_id too.
- $date = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = %s", $sermon->ID, 'sermon_date' ) );
-
- // if for some reason, the date is blank or something else, continue to next sermon
- if ( empty( $date[0] ) ) {
- continue;
- }
-
- // assign first sermon_date meta to $date variable
- $date = $date[0];
-
- // skip if we need only old dates
- if ( is_numeric( $date->meta_value ) && $filter_old ) {
- continue;
- }
-
- $posts_meta[] = array(
- 'date' => $date->meta_value,
- 'meta_id' => $date->meta_id,
- 'post_id' => $sermon->ID,
- );
- }
-
- return $posts_meta;
- }
-}
-
-try {
- $WPFC_Fix_Dates = new WPFC_Fix_Dates();
- $WPFC_Fix_Dates->init();
-} catch ( Exception $e ) {
- print_r( $e );
-}
\ No newline at end of file
diff --git a/includes/options.php b/includes/options.php
index ceada3e..b862c49 100755
--- a/includes/options.php
+++ b/includes/options.php
@@ -31,6 +31,7 @@ function wpfc_init() {
}
register_setting( 'wpfc_plugin_options', 'wpfc_options', $args );
+ wp_enqueue_media();
}
// Add menu page
@@ -99,17 +100,38 @@ function wpfc_sermon_options_render_form() {