Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/3.3.0-alpha #782

Merged
merged 4 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions assets/admin/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -977,17 +977,17 @@ textarea#episode_embed_code {
font-family: dashicons, 'Inter', sans-serif; }

/* Hide the WP bars */
.admin_page_ssp-onboarding-1 #adminmenumain, .admin_page_ssp-onboarding-1 #wpadminbar, .admin_page_ssp-onboarding-1 #wpfooter, .admin_page_ssp-onboarding-2 #adminmenumain, .admin_page_ssp-onboarding-2 #wpadminbar, .admin_page_ssp-onboarding-2 #wpfooter, .admin_page_ssp-onboarding-3 #adminmenumain, .admin_page_ssp-onboarding-3 #wpadminbar, .admin_page_ssp-onboarding-3 #wpfooter, .admin_page_ssp-onboarding-4 #adminmenumain, .admin_page_ssp-onboarding-4 #wpadminbar, .admin_page_ssp-onboarding-4 #wpfooter, .admin_page_ssp-onboarding-5 #adminmenumain, .admin_page_ssp-onboarding-5 #wpadminbar, .admin_page_ssp-onboarding-5 #wpfooter {
.podcast_page_ssp-onboarding-1 #adminmenumain, .podcast_page_ssp-onboarding-1 #wpadminbar, .podcast_page_ssp-onboarding-1 #wpfooter, .admin_page_ssp-onboarding-1 #adminmenumain, .admin_page_ssp-onboarding-1 #wpadminbar, .admin_page_ssp-onboarding-1 #wpfooter, .admin_page_ssp-onboarding-2 #adminmenumain, .admin_page_ssp-onboarding-2 #wpadminbar, .admin_page_ssp-onboarding-2 #wpfooter, .admin_page_ssp-onboarding-3 #adminmenumain, .admin_page_ssp-onboarding-3 #wpadminbar, .admin_page_ssp-onboarding-3 #wpfooter, .admin_page_ssp-onboarding-4 #adminmenumain, .admin_page_ssp-onboarding-4 #wpadminbar, .admin_page_ssp-onboarding-4 #wpfooter, .admin_page_ssp-onboarding-5 #adminmenumain, .admin_page_ssp-onboarding-5 #wpadminbar, .admin_page_ssp-onboarding-5 #wpfooter {
display: none; }

.admin_page_ssp-onboarding-1 #wpcontent, .admin_page_ssp-onboarding-2 #wpcontent, .admin_page_ssp-onboarding-3 #wpcontent, .admin_page_ssp-onboarding-4 #wpcontent, .admin_page_ssp-onboarding-5 #wpcontent {
.podcast_page_ssp-onboarding-1 #wpcontent, .admin_page_ssp-onboarding-1 #wpcontent, .admin_page_ssp-onboarding-2 #wpcontent, .admin_page_ssp-onboarding-3 #wpcontent, .admin_page_ssp-onboarding-4 #wpcontent, .admin_page_ssp-onboarding-5 #wpcontent {
margin-left: 0;
padding-left: 0; }

.admin_page_ssp-onboarding-1 #wpbody-content, .admin_page_ssp-onboarding-2 #wpbody-content, .admin_page_ssp-onboarding-3 #wpbody-content, .admin_page_ssp-onboarding-4 #wpbody-content, .admin_page_ssp-onboarding-5 #wpbody-content {
.podcast_page_ssp-onboarding-1 #wpbody-content, .admin_page_ssp-onboarding-1 #wpbody-content, .admin_page_ssp-onboarding-2 #wpbody-content, .admin_page_ssp-onboarding-3 #wpbody-content, .admin_page_ssp-onboarding-4 #wpbody-content, .admin_page_ssp-onboarding-5 #wpbody-content {
padding-bottom: 30px; }

.admin_page_ssp-onboarding-1 .notice, .admin_page_ssp-onboarding-1 .error, .admin_page_ssp-onboarding-2 .notice, .admin_page_ssp-onboarding-2 .error, .admin_page_ssp-onboarding-3 .notice, .admin_page_ssp-onboarding-3 .error, .admin_page_ssp-onboarding-4 .notice, .admin_page_ssp-onboarding-4 .error, .admin_page_ssp-onboarding-5 .notice, .admin_page_ssp-onboarding-5 .error {
.podcast_page_ssp-onboarding-1 .notice, .podcast_page_ssp-onboarding-1 .error, .admin_page_ssp-onboarding-1 .notice, .admin_page_ssp-onboarding-1 .error, .admin_page_ssp-onboarding-2 .notice, .admin_page_ssp-onboarding-2 .error, .admin_page_ssp-onboarding-3 .notice, .admin_page_ssp-onboarding-3 .error, .admin_page_ssp-onboarding-4 .notice, .admin_page_ssp-onboarding-4 .error, .admin_page_ssp-onboarding-5 .notice, .admin_page_ssp-onboarding-5 .error {
display: none; }

.ssp-review-notice {
Expand Down
2 changes: 1 addition & 1 deletion assets/admin/scss/_onboarding.scss
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@
}

/* Hide the WP bars */
.admin_page_ssp-onboarding-1, .admin_page_ssp-onboarding-2, .admin_page_ssp-onboarding-3, .admin_page_ssp-onboarding-4, .admin_page_ssp-onboarding-5 {
.podcast_page_ssp-onboarding-1, .admin_page_ssp-onboarding-1, .admin_page_ssp-onboarding-2, .admin_page_ssp-onboarding-3, .admin_page_ssp-onboarding-4, .admin_page_ssp-onboarding-5 {
#adminmenumain, #wpadminbar, #wpfooter {
display: none;
}
Expand Down
11 changes: 11 additions & 0 deletions assets/js/admin-menu.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
jQuery( document ).ready( function( $ ) {
var initOnboardingMenu = function() {
var $firstMenuItem = $( '#menu-posts-podcast' ).find( '.wp-submenu a.wp-first-item' );

if ( $firstMenuItem.length && $firstMenuItem.attr( 'href' ).includes( 'page=ssp-onboarding-1' ) ) {
$firstMenuItem.closest('ul').find('li').not('.wp-first-item').hide();
}
}

initOnboardingMenu();
} );
2 changes: 1 addition & 1 deletion php/classes/controllers/class-ads-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected function is_ads_enabled_in_castos() {

$series_id = $this->get_current_feed_series_id();

if ( empty( $podcasts['data']['podcast_list'] ) ) {
if ( ! is_array( $podcasts ) || empty( $podcasts['data']['podcast_list'] ) ) {
return false;
}

Expand Down
43 changes: 22 additions & 21 deletions php/classes/controllers/class-app-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ protected function bootstrap() {

$this->assets_controller = new Assets_Controller();

$this->series_handler = new Series_Handler( $this->admin_notices_handler, $this->roles_handler, $this->castos_handler, $this->settings_handler, $this->episode_repository );
$this->series_handler = new Series_Handler( $this->admin_notices_handler, $this->roles_handler, $this->castos_handler, $this->settings_handler, $this->episode_repository );

$this->upgrade_handler = new Upgrade_Handler( $this->episode_repository, $this->castos_handler, $this->series_handler );

Expand Down Expand Up @@ -331,7 +331,7 @@ protected function bootstrap() {
$this->load_plugin_textdomain();
}

protected function init_integrations(){
protected function init_integrations() {
/*
* Gutenberg integration.
* Only load Blocks if the WordPress version is newer than 5.0.
Expand Down Expand Up @@ -393,7 +393,7 @@ public function get_available_services() {
*
* @return string
* */
protected function get_wp_version(){
protected function get_wp_version() {
global $wp_version;

return $wp_version;
Expand All @@ -402,7 +402,7 @@ protected function get_wp_version(){
/**
* Init REST API
*/
protected function init_rest_api(){
protected function init_rest_api() {
global $wp_version;

// Only load WP REST API Endpoints if the WordPress version is newer than 4.7.
Expand Down Expand Up @@ -494,7 +494,6 @@ public function get_settings_handler() {
}



/**
* Register the Castos Blog dashboard widget
* Hooks into the wp_dashboard_setup action hook
Expand Down Expand Up @@ -547,9 +546,9 @@ public function ssp_castos_dashboard_output( $widget_id, $feeds ) {
/**
* Check if there is a cached version of the RSS Feed and output it
*/
$locale = get_user_locale();
$cache_key = 'ssp_dash_v2_' . md5( $widget_id . '_' . $locale );
$rss_output = get_transient( $cache_key );
$locale = get_user_locale();
$cache_key = 'ssp_dash_v2_' . md5( $widget_id . '_' . $locale );
$rss_output = get_transient( $cache_key );
if ( false !== $rss_output ) {
return $rss_output;
}
Expand All @@ -568,13 +567,14 @@ public function ssp_castos_dashboard_output( $widget_id, $feeds ) {
* Set up the cached version to expire in 12 hours and output the content
*/
set_transient( $cache_key, $rss_output, 12 * HOUR_IN_SECONDS );

return $rss_output;
}

/**
* Adding podcast episodes to 'At a glance' dashboard widget
*
* @param array $items Existing items
* @param array $items Existing items
*
* @return array Updated items
*/
Expand All @@ -583,8 +583,8 @@ public function glance_items( $items = array() ) {
$num_posts = count( ssp_episodes( - 1, '', false, 'glance' ) );

$post_type_object = get_post_type_object( $this->token );
$text = _n( '%s Episode', '%s Episodes', $num_posts, 'seriously-simple-podcasting' );
$text = sprintf( $text, number_format_i18n( $num_posts ) );
$text = _n( '%s Episode', '%s Episodes', $num_posts, 'seriously-simple-podcasting' );
$text = sprintf( $text, number_format_i18n( $num_posts ) );

if ( $post_type_object && current_user_can( $post_type_object->cap->edit_posts ) ) {
$items[] = sprintf( '<a class="%1$s-count" href="edit.php?post_type=%1$s">%2$s</a>', $this->token, $text ) . "\n";
Expand All @@ -598,10 +598,10 @@ public function glance_items( $items = array() ) {
/**
* Adding appreciation links to the SSP record in the plugin list table
*
* @param array $plugin_meta Default plugin meta links
* @param string $plugin_file Plugin file
* @param array $plugin_data Array of plugin data
* @param string $status Plugin status
* @param array $plugin_meta Default plugin meta links
* @param string $plugin_file Plugin file
* @param array $plugin_data Array of plugin data
* @param string $status Plugin status
*
* @return array Modified plugin meta links
*/
Expand All @@ -613,6 +613,7 @@ public function plugin_row_meta( $plugin_meta = array(), $plugin_file = '', $plu
$plugin_meta['docs'] = '<a href="https://support.castos.com/?utm_medium=sspodcasting&utm_source=wordpress&utm_campaign=wpplugin_08_2019" target="_blank">' . __( 'Documentation', 'seriously-simple-podcasting' ) . '</a>';
$plugin_meta['addons'] = '<a href="https://castos.com/add-ons/?utm_medium=sspodcasting&utm_source=wordpress&utm_campaign=wpplugin_08_2019" target="_blank">' . __( 'Add-ons', 'seriously-simple-podcasting' ) . '</a>';
$plugin_meta['review'] = '<a href="https://wordpress.org/support/view/plugin-reviews/' . $plugin_data['slug'] . '?rate=5#postform" target="_blank">' . __( 'Write a review', 'seriously-simple-podcasting' ) . '</a>';

return $plugin_meta;
}

Expand Down Expand Up @@ -650,7 +651,7 @@ public function load_plugin_textdomain() {
/**
* Hide RSS footer created by WordPress SEO from podcast RSS feed
*
* @param boolean $include_footer Default inclusion value
* @param boolean $include_footer Default inclusion value
*
* @return boolean Modified inclusion value
*/
Expand Down Expand Up @@ -710,7 +711,7 @@ public function maybe_run_plugin_updates() {
/**
* Add rating link to admin footer on SSP settings pages
*
* @param string $footer_text Default footer text
* @param string $footer_text Default footer text
*
* @return string Modified footer text
*/
Expand All @@ -722,7 +723,7 @@ public function admin_footer_text( $footer_text ) {
// Change the footer text
if ( ! get_option( 'ssp_admin_footer_text_rated' ) ) {
$footer_text = sprintf( __( 'If you like %1$sSeriously Simple Podcasting%2$s please leave a %3$s&#9733;&#9733;&#9733;&#9733;&#9733;%4$s rating. A huge thank you in advance!', 'seriously-simple-podcasting' ), '<strong>', '</strong>', '<a href="https://wordpress.org/support/plugin/seriously-simple-podcasting/reviews/?rate=5#new-post" target="_blank" class="ssp-rating-link" data-rated="' . __( 'Thanks!', 'seriously-simple-podcasting' ) . '">', '</a>' );
$footer_text .= sprintf("<script type='text/javascript'>
$footer_text .= sprintf( "<script type='text/javascript'>
(function($){
$('a.ssp-rating-link').click(function() {
$.post( '" . admin_url( 'admin-ajax.php' ) . "', { action: 'ssp_rated', nonce: '%s' } );
Expand All @@ -741,8 +742,8 @@ public function admin_footer_text( $footer_text ) {
/**
* Clear the cache on post save.
*
* @param int $id POST ID
* @param object $post WordPress Post Object
* @param int $id POST ID
* @param object $post WordPress Post Object
*
* @return void
*/
Expand Down Expand Up @@ -788,7 +789,7 @@ public function submit_import_form() {
if ( $trigger_import_submit === $submit ) {
$import = sanitize_text_field( $_POST['ss_podcasting_podmotor_import'] );
if ( 'on' === $import ) {
$result = $this->castos_handler->trigger_podcast_import();
$result = $this->castos_handler->trigger_podcast_import();
if ( 'success' !== $result['status'] ) {
add_action( 'admin_notices', array( $this, 'trigger_import_error' ) );
} else {
Expand Down
7 changes: 7 additions & 0 deletions php/classes/controllers/class-assets-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ public function enqueue_admin_styles( $hook ) {
*/
public function enqueue_admin_scripts( $hook ) {

wp_enqueue_script(
'ssp-admin-menu',
esc_url( $this->assets_url . 'js/admin-menu' . $this->script_suffix . '.js' ),
array( 'jquery' ),
$this->version
);

if ( ! $this->need_admin_scripts( $hook ) ) {
return;
}
Expand Down
45 changes: 36 additions & 9 deletions php/classes/controllers/class-cron-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,22 @@ class Cron_Controller {
* */
protected $upgrade_handler;

const SYNC_SCHEDULE_META = 'podmotor_schedule_upload';

const ATTEMPTS_META = 'castos_sync_attempts';

const MAX_ATTEMPTS = 3;

/**
* @param Castos_Handler $castos_handler
* @param Episode_Repository $episodes_respository
* @param Upgrade_Handler $upgrade_handler
*/
public function __construct( $castos_handler, $episodes_respository, $upgrade_handler ) {

$this->castos_handler = $castos_handler;
$this->castos_handler = $castos_handler;
$this->episodes_respository = $episodes_respository;
$this->upgrade_handler = $upgrade_handler;
$this->upgrade_handler = $upgrade_handler;

add_action( 'admin_init', array( $this, 'schedule_events' ) );
add_filter( 'cron_schedules', array( $this, 'add_cron_intervals' ) );
Expand All @@ -55,7 +61,7 @@ public function __construct( $castos_handler, $episodes_respository, $upgrade_ha
/**
* @return void
*/
protected function run_actions(){
protected function run_actions() {
add_action( 'ssp_cron_hook', array( $this, 'upload_scheduled_episodes' ) );
$this->upgrade_handler->run_upgrade_actions();
}
Expand All @@ -80,7 +86,7 @@ public function schedule_events() {
if ( ! wp_next_scheduled( 'ssp_cron_hook' ) ) {
wp_schedule_event( time(), 'hourly', 'ssp_cron_hook' );
}
if( ! wp_next_scheduled('ssp_check_ads') ){
if ( ! wp_next_scheduled( 'ssp_check_ads' ) ) {
wp_schedule_event( time(), 'daily', 'ssp_check_ads' );
}
}
Expand All @@ -90,19 +96,36 @@ public function schedule_events() {
*/
public function upload_scheduled_episodes() {
$uploaded = 0;
$logger = new Log_Helper();
$logger = new Log_Helper();

foreach ( $this->episodes_respository->get_scheduled_episodes() as $episode ) {
$response = $this->castos_handler->upload_episode_to_castos( $episode );

if ( 'success' === $response['status'] ) {
delete_post_meta( $episode->ID, 'podmotor_schedule_upload' );
$this->unschedule_episode( $episode->ID );
$this->episodes_respository->update_episode_sync_status( $episode->ID, Sync_Status::SYNC_STATUS_SYNCED );
$this->episodes_respository->delete_episode_sync_error( $episode->ID );
$uploaded++;
$uploaded ++;
} else {
$attempts = get_post_meta( $episode->ID, self::ATTEMPTS_META, true );
if ( $attempts < self::MAX_ATTEMPTS ) {
update_post_meta( $episode->ID, self::ATTEMPTS_META, ++ $attempts );
} else {
$this->unschedule_episode( $episode->ID );
}
}

if ( 404 == $response['code'] ) {
delete_post_meta( $episode->ID, 'podmotor_schedule_upload' );
if ( isset( $response['code'] ) && 404 == $response['code'] ) {
$castos_episode_id = get_post_meta( $episode->ID, 'podmotor_episode_id', true );

// Episode does not exists anymore, remove connection
if ( $castos_episode_id ) {
delete_post_meta( $episode->ID, 'podmotor_episode_id' );
delete_post_meta( $episode->ID, 'podmotor_file_id' );
}

$this->unschedule_episode( $episode->ID );

$logger->log( sprintf( 'Cron: could not upload episode %d', $episode->ID ) );
}
}
Expand All @@ -113,4 +136,8 @@ public function upload_scheduled_episodes() {

return $uploaded;
}

protected function unschedule_episode( $episode_id ) {
delete_post_meta( $episode_id, self::SYNC_SCHEDULE_META );
}
}
31 changes: 22 additions & 9 deletions php/classes/controllers/class-onboarding-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct( $renderer, $settings_handler ) {
* Fix PHP deprecated warning for new WordPress installations on the first onboarding step.
* */
public function fix_deprecated_warning() {
$page = filter_input(INPUT_GET, 'page');
$page = filter_input( INPUT_GET, 'page' );
if ( $page && ( false !== strpos( $page, self::ONBOARDING_BASE_SLUG ) ) ) {
global $title;
if ( ! isset( $title ) ) {
Expand All @@ -75,8 +75,7 @@ public function maybe_start_onboarding( $plugin ) {
if ( $plugin !== plugin_basename( $this->file ) ) {
return;
}
$title = ssp_get_option( 'data_title', '', ssp_get_default_series_id() );
if ( ! $title ) {
if ( ! ssp_onboarded() ) {
wp_redirect( admin_url( sprintf( 'admin.php?page=%s-1', self::ONBOARDING_BASE_SLUG ) ) );
exit();
}
Expand All @@ -87,16 +86,28 @@ public function enqueue_scripts() {
if ( false !== strpos( $screen->base, self::ONBOARDING_BASE_SLUG ) ) {
wp_enqueue_media();
wp_enqueue_script( 'ssp-onboarding', esc_url( $this->assets_url . 'admin/js/onboarding' . $this->script_suffix . '.js' ), array(
'jquery'
'jquery',
), $this->version );
}
}

public function register_pages() {
if ( ! ssp_onboarded() ) {
add_submenu_page(
'edit.php?post_type=' . SSP_CPT_PODCAST,
__( 'Onboarding Wizard', 'seriously-simple-podcasting' ),
__( 'Onboarding Wizard', 'seriously-simple-podcasting' ),
'manage_podcast',
'ssp-onboarding-1',
array( $this, 'step_1' ),
0
);
}

for ( $page_number = 1; $page_number <= self::STEPS_NUMBER; $page_number ++ ) {
$this->register_page( 'Onboarding wizzard', $this->get_page_slug( $page_number ), array(
$this->register_page( 'Onboarding wizard', $this->get_page_slug( $page_number ), array(
$this,
sprintf( 'step_%s', $page_number )
sprintf( 'step_%s', $page_number ),
) );
}
}
Expand Down Expand Up @@ -174,7 +185,7 @@ protected function get_step_data( $step_number ) {
$step_urls[ $page_number ] = $this->get_step_url( $page_number );
}
$data['step_urls'] = $step_urls;
$series_id = ( 4 === $step_number ) ? 0 : ssp_get_default_series_id();
$series_id = ( 4 === $step_number ) ? 0 : ssp_get_default_series_id();

foreach ( $this->get_step_fields( $step_number ) as $field_name ) {
$data[ $field_name ] = ssp_get_option( $field_name, '', $series_id );
Expand Down Expand Up @@ -232,11 +243,12 @@ protected function save_step( $step_number ) {
foreach ( $this->get_step_fields( $step_number ) as $field_id ) {
$val = filter_input( INPUT_POST, $field_id );
if ( $val ) {
$val = esc_html( strip_tags( $val ) );
ssp_update_option( $field_id, $val, $series_id );
}
}

if( 1 === $step_number ){
if ( 1 === $step_number ) {
$this->update_default_series_name( $default_series_id );
ssp_add_option( 'series_slug', CPT_Podcast_Handler::DEFAULT_SERIES_SLUG );
}
Expand All @@ -249,8 +261,9 @@ protected function save_step( $step_number ) {
*/
protected function update_default_series_name( $series_id ) {
$series = get_term_by( 'id', $series_id, ssp_series_taxonomy() );
$name = ssp_get_option( 'data_title', get_bloginfo('name'), $series_id );
$name = ssp_get_option( 'data_title', get_bloginfo( 'name' ), $series_id );
$slug = wp_unique_term_slug( sanitize_title( $name ), $series );

return wp_update_term( $series_id, ssp_series_taxonomy(), array(
'name' => $name,
'slug' => $slug,
Expand Down
Loading
Loading