plugin_name = $plugin_name; $this->version = $version; } /** * Get and set the options * * @return mixed|string|void */ protected function get_options(){ if( is_null( $this->options ) ){ $this->options = get_option( $this->option_name ); } return $this->options; } /** * Get a option value if it exists * * @param $option * @return bool|string|void */ public function av_get_option_value( $option ){ $options = $this->get_options(); if( !isset( $options[$option] ) ){ return false; } return esc_attr( $options[$option] ); } /** * Add custom css styles */ public function custom_css_styles(){ include_once plugin_dir_path( dirname( __FILE__ ) ) . '/public/partials/amp-customizer-public-css.php'; } public function check_settings_callbacks(){ $settings = $this->get_options(); if( !$settings ){ return false; } foreach( $settings as $setting => $state ){ if( empty( $setting ) || empty( $state ) ){ continue; } $callback = $setting . '_callback'; if( !method_exists( $this, $callback ) ){ continue; } $this->$callback( $state ); } } /** * Should we add the featured image? * * @param $state */ protected function add_featured_image_callback( $state ){ if( $state == 1 ){ add_filter( 'the_content', array( $this, 'add_featured_image' ) ); } } /** * Add the featured image * * @param $content * @return string */ public function add_featured_image( $content ) { if ( has_post_thumbnail() ) { $image = sprintf( '', get_the_post_thumbnail() ); $content = $image . $content; } return $content; } /** * Change the content max width? * * @param $state */ public function content_max_width_callback( $state ){ if( !empty($state) && $state > 0 ){ add_filter( 'amp_content_max_width', array( $this, 'change_content_max_width' ) ); } } /** * Change the content max width * * @param $content_max_width * @return mixed */ public function change_content_max_width( $content_max_width ){ $options = $this->get_options(); if( isset( $options['content_max_width'] ) ){ $content_max_width = $options['content_max_width']; } return $content_max_width; } }