render(); if ( isset( $_REQUEST[ '_wpnonce' ] ) && wp_verify_nonce( $_REQUEST[ '_wpnonce' ] ) ) { $settings = get_option( 'adfoxly_settings' ); if ( isset( $_REQUEST[ '_wpnonce' ] ) && wp_verify_nonce( $_REQUEST[ '_wpnonce' ] ) ) { if ( $_POST[ 'adfoxly-redirect-slug' ] ) { if ( ! isset( $settings[ 'redirect-slug' ] ) || empty( $settings[ 'redirect-slug' ] ) || $_POST[ 'adfoxly-redirect-slug' ] !== $settings[ 'redirect-slug' ] ) { $settings[ 'redirect-slug' ] = sanitize_text_field( $_POST[ 'adfoxly-redirect-slug' ] ); update_option( 'adfoxly_settings', $settings ); flush_rewrite_rules( true ); global $wp_rewrite; $wp_rewrite->flush_rules(); } } if ( isset( $_POST[ 'adfoxly-facebook-pixel-code' ] ) ) { // here we need add html code, cannot use sanitize_text_field $settings[ 'adfoxly-facebook-pixel-code' ] = wp_kses_post( $_POST[ 'adfoxly-facebook-pixel-code' ] ); update_option( 'adfoxly_settings', $settings ); } if ( isset( $_POST[ 'adfoxly-privacy-heap' ] ) ) { // here we need add html code, cannot use sanitize_text_field $settings[ 'adfoxly-privacy-heap' ] = wp_kses_post( $_POST[ 'adfoxly-privacy-heap' ] ); update_option( 'adfoxly_settings', $settings ); } if ( isset( $_POST[ 'adfoxly-privacy-hotjar' ] ) ) { // here we need add html code, cannot use sanitize_text_field $settings[ 'adfoxly-privacy-hotjar' ] = wp_kses_post( $_POST[ 'adfoxly-privacy-hotjar' ] ); update_option( 'adfoxly_settings', $settings ); } if ( isset( $_POST[ 'adfoxly-privacy-ga' ] ) ) { // here we need add html code, cannot use sanitize_text_field $settings[ 'adfoxly-privacy-ga' ] = wp_kses_post( $_POST[ 'adfoxly-privacy-ga' ] ); update_option( 'adfoxly_settings', $settings ); } if ( isset( $_POST[ 'adfoxly-privacy-yandex' ] ) ) { // here we need add html code, cannot use sanitize_text_field $settings[ 'adfoxly-privacy-yandex' ] = wp_kses_post( $_POST[ 'adfoxly-privacy-yandex' ] ); update_option( 'adfoxly_settings', $settings ); } if ( isset( $_POST[ 'adfoxly-privacy-sentry' ] ) ) { // here we need add html code, cannot use sanitize_text_field $settings[ 'adfoxly-privacy-sentry' ] = wp_kses_post( $_POST[ 'adfoxly-privacy-sentry' ] ); update_option( 'adfoxly_settings', $settings ); } if ( $_POST[ 'adfoxly-statistics-status' ] ) { if ( ! isset( $settings[ 'statistics-status' ] ) || empty( $settings[ 'statistics-status' ] ) || $_POST[ 'adfoxly-statistics-status' ] !== $settings[ 'statistics-status' ] ) { $settings[ 'statistics-status' ] = sanitize_text_field( $_POST[ 'adfoxly-statistics-status' ] ); update_option( 'adfoxly_settings', $settings ); if ( $_POST[ 'adfoxly-statistics-status' ] === 'enabled' ) { $statistics = new StatisticsController(); $statistics->insertTables(); } } } if ( $_POST[ 'adfoxly-statistics-type' ] ) { if ( $_POST[ 'adfoxly-statistics-type' ] !== $settings[ 'statistics-type' ] ) { $settings[ 'statistics-type' ] = sanitize_text_field( $_POST[ 'adfoxly-statistics-type' ] ); update_option( 'adfoxly_settings', $settings ); } } if ( isset( $_POST[ 'adfoxly-statistics-gaid-select' ] ) && ! empty( $_POST[ 'adfoxly-statistics-gaid-select' ] ) ) { if ( $_POST[ 'adfoxly-statistics-gaid-select' ] !== $settings[ 'statistics-gaid-select' ] ) { $settings[ 'statistics-gaid-select' ] = sanitize_text_field( $_POST[ 'adfoxly-statistics-gaid-select' ] ); update_option( 'adfoxly_settings', $settings ); } } if ( isset( $_POST[ 'adfoxly-statistics-custom-gaid' ] ) && ! empty( $_POST[ 'adfoxly-statistics-custom-gaid' ] ) ) { if ( $_POST[ 'adfoxly-statistics-custom-gaid' ] !== $settings[ 'statistics-custom-gaid' ] ) { $settings[ 'statistics-custom-gaid' ] = sanitize_text_field( $_POST[ 'adfoxly-statistics-custom-gaid' ] ); update_option( 'adfoxly_settings', $settings ); } } if ( isset( $_POST[ 'adfoxly-statistics-saving-view-interval' ] ) && ( ! empty( $_POST[ 'adfoxly-statistics-saving-view-interval' ] ) || $_POST[ 'adfoxly-statistics-saving-view-interval' ] === '0' ) ) { if ( sanitize_text_field( $_POST[ 'adfoxly-statistics-saving-view-interval' ] ) !== $settings[ 'statistics-saving-view-interval' ] ) { $settings[ 'statistics-saving-view-interval' ] = sanitize_text_field( $_POST[ 'adfoxly-statistics-saving-view-interval' ] ); update_option( 'adfoxly_settings', $settings ); } } } } class statisticsMetabox { private $meta_fields = array( array( 'label' => 'test123', 'id' => 'test-_id', 'type' => 'text', ), ); public function __construct() { } public function meta_box_callback( $post ) { wp_nonce_field( 'statistics_data', 'statistics_nonce' ); $this->field_generator( $post ); } public function field_generator( $post ) { $output = ''; foreach ( $this->meta_fields as $meta_field ) { $label = ''; $meta_value = get_post_meta( $post->ID, $meta_field[ 'id' ], true ); if ( empty( $meta_value ) ) { $meta_value = $meta_field[ 'default' ]; } switch ( $meta_field[ 'type' ] ) { default: $input = sprintf( '', $meta_field[ 'type' ] !== 'color' ? 'style="width: 100%"' : '', $meta_field[ 'id' ], $meta_field[ 'id' ], $meta_field[ 'type' ], $meta_value ); } $output .= $this->format_rows( $label, $input ); } echo '' . $output . '
'; } public function format_rows( $label, $input ) { return '' . $label . '' . $input . ''; } public function save_fields( $post_id ) { if ( ! isset( $_POST[ 'statistics_nonce' ] ) ) { return $post_id; } $nonce = $_POST[ 'statistics_nonce' ]; if ( ! wp_verify_nonce( $nonce, 'statistics_data' ) ) { return $post_id; } if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $post_id; } foreach ( $this->meta_fields as $meta_field ) { if ( isset( $_POST[ $meta_field[ 'id' ] ] ) ) { switch ( $meta_field[ 'type' ] ) { case 'email': $_POST[ $meta_field[ 'id' ] ] = sanitize_email( $_POST[ $meta_field[ 'id' ] ] ); break; case 'text': $_POST[ $meta_field[ 'id' ] ] = sanitize_text_field( $_POST[ $meta_field[ 'id' ] ] ); break; } update_post_meta( $post_id, sanitize_text_field( $meta_field[ 'id' ] ), sanitize_text_field( $_POST[ $meta_field[ 'id' ] ] ) ); } else if ( $meta_field[ 'type' ] === 'checkbox' ) { update_post_meta( $post_id, sanitize_text_field( $meta_field[ 'id' ] ), '0' ); } } } } //if ( class_exists( 'statisticsMetabox' ) ) { // new statisticsMetabox; //}; $settings = get_option( 'adfoxly_settings' ); $form = new adfoxlyForm(); ?>
generate( array( 'type' => 'settings_redirect' ) ); ?>
generate( array( 'type' => 'settings_statistics' ) ); ?>
generate( array( 'type' => 'settings_pixel' ) ); ?>
generate( array( 'type' => 'settings_privacy' ) ); ?>
"/>