EDULE, array() ) ) ); $query = new WP_Query( $query_args ); while ( $query->have_posts() ) { $chart_id = $query->next_post(); $type = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_TYPE, true ); $charts['types'][ $type ] = isset( $charts['types'][ $type ] ) ? $charts['types'][ $type ] + 1 : 1; $source = get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ); $charts['sources'][ $source ] = isset( $charts['sources'][ $source ] ) ? $charts['sources'][ $source ] + 1 : 1; $lib = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_LIBRARY, true ); $charts['library'][ $lib ] = isset( $charts['library'][ $lib ] ) ? $charts['library'][ $lib ] + 1 : 1; $settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ); if ( array_key_exists( 'manual', $settings ) && ! empty( $settings['manual'] ) ) { $charts['manual_config'] = $charts['manual_config'] + 1; } // phpcs:ignore WordPress.PHP.StrictInArray.FoundNonStrictFalse if ( in_array( $chart_id, $scheduled, false ) ) { $charts['scheduled'] = $charts['scheduled'] + 1; } if ( Visualizer_Module::is_pro() ) { $permissions = get_post_meta( $chart_id, Visualizer_PRO::CF_PERMISSIONS, true ); if ( empty( $permissions ) ) { continue; } $permissions = $permissions['permissions']; $customized = false; foreach ( $default_perms as $key => $val ) { if ( ! is_array( $val ) && ! is_null( $val ) && isset( $permissions[ $key ] ) && $permissions[ $key ] !== $val ) { $customized = true; } elseif ( is_array( $val ) && ! is_null( $val ) && isset( $permissions[ $key ] ) && count( $permissions[ $key ] ) !== count( $val ) ) { $customized = true; } } if ( $customized ) { $charts['permissions'] = $charts['permissions'] + 1; } } if ( ! empty( $meta_keys ) ) { foreach ( $meta_keys as $name => $key ) { $data = get_post_meta( $chart_id, $key, true ); if ( ! empty( $data ) ) { $charts[ $name ] = isset( $charts[ $name ] ) ? $charts[ $name ] + 1 : 1; } else { $charts[ $name ] = 0; } } } } return $charts; } /** * Registers custom post type for charts. * * @since 1.0.0 * @uses register_post_type() To register custom post type for charts. * * @access public */ public function setupCustomPostTypes() { register_post_type( Visualizer_Plugin::CPT_VISUALIZER, array( 'label' => 'Visualizer Charts', 'public' => false, 'supports' => array( 'revisions' ), 'show_in_rest' => true, 'rest_base' => 'visualizer', 'rest_controller_class' => 'WP_REST_Posts_Controller', ) ); } /** * Loads plugin text domain translations. * * @since 1.0.0 * @uses load_plugin_textdomain() To load translations for the plugin. * * @access public */ public function loadTextDomain() { load_plugin_textdomain( Visualizer_Plugin::NAME, false, dirname( plugin_basename( VISUALIZER_BASEFILE ) ) . '/languages/' ); } /** * Activate the plugin */ public function activate( $network_wide ) { if ( is_multisite() && $network_wide ) { foreach ( get_sites( array( 'fields' => 'ids' ) ) as $blog_id ) { switch_to_blog( $blog_id ); $this->activate_on_site(); restore_current_blog(); } } else { $this->activate_on_site(); } } /** * Activates the plugin on a particular blog instance (supports multisite and single site). */ private function activate_on_site() { wp_clear_scheduled_hook( 'visualizer_schedule_refresh_db' ); wp_schedule_event( strtotime( 'midnight' ) - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS, apply_filters( 'visualizer_chart_schedule_interval', 'visualizer_ten_minutes' ), 'visualizer_schedule_refresh_db' ); add_option( 'visualizer-activated', true ); $is_fresh_install = get_option( 'visualizer_fresh_install', false ); if ( ! defined( 'TI_CYPRESS_TESTING' ) && false === $is_fresh_install ) { update_option( 'visualizer_fresh_install', '1' ); } } /** * Deactivate the plugin */ public function deactivate( $network_wide ) { if ( is_multisite() && $network_wide ) { foreach ( get_sites( array( 'fields' => 'ids' ) ) as $blog_id ) { switch_to_blog( $blog_id ); $this->deactivate_on_site(); restore_current_blog(); } } else { $this->deactivate_on_site(); } } /** * Deactivates the plugin on a particular blog instance (supports multisite and single site). */ private function deactivate_on_site() { wp_clear_scheduled_hook( 'visualizer_schedule_refresh_db' ); delete_option( 'visualizer-activated', true ); } /** * Check if plugin has been activated and then redirect to the correct page. */ public function adminInit() { if ( defined( 'TI_UNIT_TESTING' ) ) { return; } define( 'VISUALIZER_SURVEY', Visualizer_Module::is_pro() ? 'https://forms.gle/7Zo7FuZbvQ8DTvRi6' : 'https://forms.gle/muMtbcyvHn1aTvmJ7' ); // fire any upgrades necessary. Visualizer_Module_Upgrade::upgrade(); if ( get_option( 'visualizer-activated' ) ) { delete_option( 'visualizer-activated' ); if ( ! headers_sent() ) { if ( ! Visualizer_Module::is_pro() && ! empty( get_option( 'visualizer_fresh_install', false ) ) ) { $redirect_url = array( 'page' => 'visualizer-setup-wizard', 'tab' => '#step-1', ); } else { $page_name = Visualizer_Module::numberOfCharts() > 0 ? Visualizer_Plugin::NAME : 'viz-support'; $redirect_url = array( 'page' => $page_name, ); } wp_safe_redirect( add_query_arg( $redirect_url, admin_url( 'admin.php' ) ) ); exit(); } } } /** * Refresh the specific chart from the db. * * @param WP_Post|null $chart The chart object. * @param int $chart_id The chart id. * @param bool $force If this is true, then the chart data will be force refreshed. If false, data will be refreshed only if the chart requests live data. * * @access public */ public function refresh_db_for_chart( $chart, $chart_id, $force = false ) { if ( ! $chart_id ) { return $chart; } if ( ! $chart ) { $chart = get_post( $chart_id ); } if ( ! $chart ) { return $chart; } // check if the source is correct. $source = get_post_meta( $chart_id, Visualizer_Plugin::CF_SOURCE, true ); $load_series = false; switch ( $source ) { case 'Visualizer_Source_Query': // check if its a live-data chart or a cached-data chart. if ( ! $force ) { $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true ); if ( ! empty( $hours ) ) { // cached, bail! return $chart; } } $params = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_QUERY, true ); $source = new Visualizer_Source_Query( $params, $chart_id ); $source->fetch( false ); $load_series = true; break; case 'Visualizer_Source_Json': // check if its a live-data chart or a cached-data chart. if ( ! $force ) { $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_SCHEDULE, true ); if ( ! empty( $hours ) ) { // cached, bail! return $chart; } } $url = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_URL, true ); $root = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_ROOT, true ); $paging = get_post_meta( $chart_id, Visualizer_Plugin::CF_JSON_PAGING, true ); $series = get_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, true ); $source = new Visualizer_Source_Json( array( 'url' => $url, 'root' => $root, 'paging' => $paging ) ); $source->refresh( $series ); break; case 'Visualizer_Source_Csv_Remote': // check if its a live-data chart or a cached-data chart. if ( ! $force ) { $hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_CHART_SCHEDULE, true ); if ( ! empty( $hours ) ) { // cached, bail! return $chart; } } do_action( 'visualizer_schedule_import' ); return get_post( $chart_id ); default: return $chart; } $error = $source->get_error(); if ( empty( $error ) ) { $this->disableRevisionsTemporarily(); if ( $load_series ) { update_post_meta( $chart_id, Visualizer_Plugin::CF_SERIES, $source->getSeries() ); } $allow_html = false; $settings = get_post_meta( $chart_id, Visualizer_Plugin::CF_SETTINGS, true ); if ( isset( $settings['allowHtml'] ) && intval( $settings['allowHtml'] ) === 1 ) { $allow_html = true; } $allow_html = apply_filters( 'visualizer_allow_html_content', $allow_html, $chart_id, $chart ); if ( $allow_html ) { kses_remove_filters(); } wp_update_post( array( 'ID' => $chart_id, 'post_content' => $source->getData( get_post_meta( $chart_id, Visualizer_Plugin::CF_EDITABLE_TABLE, true ) ), ) ); if ( $allow_html ) { kses_init_filters(); } $chart = get_post( $chart_id ); delete_post_meta( $chart_id, Visualizer_Plugin::CF_ERROR ); } else { update_post_meta( $chart_id, Visualizer_Plugin::CF_ERROR, sprintf( 'Error while updating chart: %s', $error ) ); } return $chart; } /** * Refresh the Database chart type. * * @access public */ public function refreshDbChart() { // NOTE: This use a different key from normal schedule. Updated only by Database chart. Check `visualizer_schedule_import` action. $chart_schedules = get_option( Visualizer_Plugin::CF_DB_SCHEDULE, array() ); if ( ! $chart_schedules ) { return; } if ( ! defined( 'VISUALIZER_DO_NOT_DIE' ) ) { // define this so that the ajax call does not die // this means that if the new version of pro and the old version of free are installed, only the first chart will be updated define( 'VISUALIZER_DO_NOT_DIE', true ); } $new_schedules = array(); $current_time = time(); foreach ( $chart_schedules as $chart_id => $scheduled_time ) { // Skip deleted charts. if ( false === get_post_status( $chart_id ) ) { continue; } $new_schedules[ $chart_id ] = $scheduled_time; // Should we do an update? if ( $scheduled_time > $current_time ) { continue; } $this->refresh_db_for_chart( null, $chart_id, true ); // Clear existing chart cache. $cache_key = Visualizer_Plugin::CF_CHART_CACHE . '_' . $chart_id; if ( get_transient( $cache_key ) ) { delete_transient( $cache_key ); } $scheduled_hours = get_post_meta( $chart_id, Visualizer_Plugin::CF_DB_SCHEDULE, true ); $new_schedules[ $chart_id ] = $current_time + $scheduled_hours * HOUR_IN_SECONDS; } update_option( Visualizer_Plugin::CF_DB_SCHEDULE, $new_schedules ); } /** * Save flag for existing users. */ public function checkIsExistingUser() { $chart_exists = get_option( 'visualizer-new-user', '' ); if ( '' === $chart_exists ) { $charts = get_posts( array( 'post_type' => Visualizer_Plugin::CPT_VISUALIZER, 'fields' => 'ids', ) ); update_option( 'visualizer-new-user', ! empty( $charts ) ? 'no' : 'yes' ); } } /** * Add custom cron schedules. * * @param array $schedules The current schedules options. * @return array The modified schedules options. */ public function custom_cron_schedules( $schedules ) { $schedules['visualizer_ten_minutes'] = array( 'interval' => 600, 'display' => __( 'Every 10 minutes', 'visualizer' ), ); return $schedules; } }
Fatal error: Uncaught Error: Class "Visualizer_Module_Setup" not found in /htdocs/wp-content/plugins/visualizer/index.php:117 Stack trace: #0 /htdocs/wp-content/plugins/visualizer/index.php(222): visualizer_launch() #1 /htdocs/wp-settings.php(526): include_once('/htdocs/wp-cont...') #2 /htdocs/wp-config.php(100): require_once('/htdocs/wp-sett...') #3 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #4 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #5 /htdocs/index.php(17): require('/htdocs/wp-blog...') #6 {main} thrown in /htdocs/wp-content/plugins/visualizer/index.php on line 117