settings = new ConvertKit_Settings(); if ( ! $this->settings->has_access_and_refresh_token() ) { return; } // Bail if the Enable Export Actions setting is not enabled. $this->broadcasts_settings = new ConvertKit_Settings_Broadcasts(); if ( ! $this->broadcasts_settings->enabled_export() ) { return; } // Run action, if selected. add_action( 'init', array( $this, 'run_row_action' ) ); // Add action below Post Title in WP_List_Table classes. add_filter( 'page_row_actions', array( $this, 'add_row_action' ), 10, 2 ); add_filter( 'post_row_actions', array( $this, 'add_row_action' ), 10, 2 ); } /** * Checks if a Plugin row action was clicked by the User, and if so performs that action. * * @since 2.4.0 */ public function run_row_action() { // Bail if no nonce exists or fails verification. if ( ! array_key_exists( 'nonce', $_REQUEST ) ) { return; } if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_REQUEST['nonce'] ) ), 'action-convertkit-' . $this->action_name ) ) { return; } // If no action or ID specified, return. if ( ! isset( $_REQUEST['convertkit-action'] ) ) { return; } if ( ! isset( $_REQUEST['id'] ) ) { return; } // Fetch action and post ID. $action = sanitize_text_field( wp_unslash( $_REQUEST['convertkit-action'] ) ); $post_id = absint( $_REQUEST['id'] ); // Bail if the action isn't for exporting a post. if ( $action !== $this->action_name ) { return; } // Bail if the current user cannot edit the Post being exported. if ( ! current_user_can( 'edit_post', $post_id ) ) { wp_die( esc_html__( 'Sorry, you are not allowed to export this Post.', 'convertkit' ) ); } // Export Post to a draft ConvertKit Broadcast. $result = $this->export_post_to_broadcast( $post_id ); // If an error occurred, display an error message. if ( is_wp_error( $result ) ) { wp_die( esc_html( $result->get_error_message() ) ); } // Store Broadcast ID for success notice. $this->broadcast_id = $result['id']; // Display a success notice with a link to editing the Broadcast on ConvertKit. add_action( 'admin_notices', array( $this, 'output_success_notice' ) ); } /** * Outputs a success notice in the WordPress Administration interface that the Post was * successfully created in ConvertKit as a Broadcast, with a link to edit in ConvertKit. * * @since 2.4.0 */ public function output_success_notice() { // Bail if no Broadcast ID specified. if ( ! $this->broadcast_id ) { return; } // Output success notice. ?>
%s %s', esc_html__( 'Successfully created Kit Broadcast from Post.', 'convertkit' ), esc_url( convertkit_get_edit_broadcast_url( $this->broadcast_id ) ), esc_html__( 'Click here', 'convertkit' ), esc_html__( 'to edit and send the broadcast in Kit.', 'convertkit' ) ); ?>