' . esc_html__( 'WARNING: error defining Custom Field on Page with Posts.', 'absolute-weaver' ) . '' ); if ( strlen( $info ) > 0 ) { echo( 'More info: ' . $info . '
' ); } } // # PAGE WITH POSTS ============================================================== function aweaver_get_page() { /* get the current posts display number needed for when Page with Posts is front page */ $paged = get_query_var( 'paged' ); if ( ! isset( $paged ) || empty( $paged ) ) { $paged = 1; } $page = get_query_var( 'page' ); if ( $page > 1 ) { $paged = $page; } return $paged; } function aweaver_setup_post_args( $args ) { /* setup WP_Query arg list */ $cats = aweaver_get_page_categories(); if ( ! empty( $cats ) ) { $args['cat'] = $cats; } $tags = aweaver_get_page_tags(); if ( ! empty( $tags ) ) { $args['tag'] = $tags; } $onepost = aweaver_get_page_onepost(); if ( ! empty( $onepost ) ) { $args['name'] = $onepost; } $orderby = aweaver_get_page_orderby(); if ( ! empty( $orderby ) ) { $args['orderby'] = $orderby; } $order = aweaver_get_page_order(); if ( ! empty( $order ) ) { $args['order'] = $order; } $author_name = aweaver_get_page_author(); if ( ! empty( $author_name ) ) { $nosp = str_replace( ' ', '', $author_name ); $id_list = str_replace( ',', '', $nosp ); if ( is_numeric( $id_list ) ) { $args['author'] = $author_name; } else { $args['author_name'] = $author_name; } } $posts_per_page = aweaver_get_page_posts_per(); if ( ! empty( $posts_per_page ) ) { $args['posts_per_page'] = $posts_per_page; } $post_type = aweaver_get_per_page_value( '_pp_post_type' ); if ( $post_type ) { $args['post_type'] = $post_type; } if ( aweaver_is_checked_page_opt( '_pp_hide_sticky' ) ) { $args['ignore_sticky_posts'] = true; } return $args; } function aweaver_get_page_categories() { $cats = aweaver_get_per_page_value( '_pp_category' ); if ( empty( $cats ) ) { return ''; } // now convert slugs to ids return aweaver_cat_slugs_to_ids( $cats ); } function aweaver_cat_slugs_to_ids( $cats ) { if ( empty( $cats ) ) { return ''; } // now convert slugs to numbers $cats = str_replace( ' ', '', $cats ); $clist = explode( ',', $cats ); // break into a list $cat_list = ''; foreach ( $clist as $slug ) { $neg = 1; // not negative if ( $slug[0] == '-' ) { $slug = substr( $slug, 1 ); // zap the - $neg = - 1; } if ( strlen( $slug ) > 0 && is_numeric( $slug ) ) { // allow both slug and id $cat_id = $neg * ( int ) $slug; if ( $cat_list == '' ) { $cat_list = strval( $cat_id ); } else { $cat_list .= ',' . strval( $cat_id ); } } else { $cur_cat = get_category_by_slug( $slug ); if ( is_object( $cur_cat ) ) { $cat_id = $neg * ( int ) $cur_cat->cat_ID; if ( $cat_list == '' ) { $cat_list = strval( $cat_id ); } else { $cat_list .= ',' . strval( $cat_id ); } } } } if ( empty( $cat_list ) ) { $cat_list = '99999999'; } return $cat_list; } function aweaver_get_page_tags() { $tags = aweaver_get_per_page_value( '_pp_tag' ); if ( empty( $tags ) ) { return ''; } return str_replace( ' ', '', $tags ); } function aweaver_get_page_onepost() { $the_post = aweaver_get_per_page_value( '_pp_onepost' ); if ( empty( $the_post ) ) { return ''; } return $the_post; } function aweaver_get_page_orderby() { $orderby = aweaver_get_per_page_value( '_pp_orderby' ); if ( empty( $orderby ) ) { return ''; } if ( $orderby == 'author' || $orderby == 'date' || $orderby == 'title' || $orderby == 'rand' ) { return $orderby; } aweaver_page_posts_error( esc_html__( 'orderby must be author, date, title, or rand. You used: ', 'absolute-weaver' ) . $orderby ); return ''; } function aweaver_get_page_order() { $order = aweaver_get_per_page_value( '_pp_sort_order' ); if ( empty( $order ) ) { return ''; } if ( $order == 'ASC' || $order == 'DESC' ) { return $order; } aweaver_page_posts_error( esc_html__( 'order value must be ASC or DESC. You used: ', 'absolute-weaver' ) . $order ); return ''; } function aweaver_get_page_posts_per() { $ppp = aweaver_get_per_page_value( '_pp_posts_per_page' ); if ( empty( $ppp ) ) { return ''; } // now convert slugs to numbers return $ppp; } function aweaver_get_page_author() { $author = aweaver_get_per_page_value( '_pp_author' ); if ( empty( $author ) ) { return ''; } return $author; } // # FILTERS ============================================================== // ============ validation filters =============== function aweaver_filter_textarea( $text ) { // virtually all option text input from Absolute Weaver can be code, and thus must not be // content filtered. Treat like code for now.... return aweaver_filter_code( $text ); } function aweaver_filter_head( $text ) { $allowed_head_tags = array( 'title' => array(), 'style' => array( 'media' => true, 'scoped' => true, 'type' => true ), 'meta' => array( 'charset' => true, 'content' => true, 'http-equiv' => true, 'name' => true, 'scheme' => true, 'property' => true, ), 'link' => array( 'href' => true, 'rel' => true, 'type' => true, 'title' => true, 'media' => true, 'id' => true, 'class' => true, 'sizes' => true, 'crossorigin' => true, 'hreflang' => true ), 'script' => array( 'async' => true, 'charset' => true, 'defer' => true, 'src' => true, 'type' => true ), 'noscript' => array(), 'base' => array( 'href' => true, 'target' => true ), ); // restrict head code to valid stuff for $noslash = trim( stripslashes( $text ) ); if ( $noslash == '' ) { return ''; } if ( current_user_can( 'unfiltered_html' ) ) { if ( strpos( $noslash, 's from being broken return wp_kses( $noslash, $allowed_head_tags ); } else { return ''; } } function aweaver_filter_code( $text ) { // Much option input from Absolute Weaver can be code, and thus must not be // content filtered - at least for admins. The utf8 check is about the extent of it, although even // that is more restrictive than the standard text widget uses. // Note: this check also works OK for simple checkboxes/radio buttons/selections, // so it is ok to blindly pass those options in here, too. //$noslash = trim( stripslashes( $text ) ); $trimmed = trim( $text ); if ( $trimmed == ' ' ) { return ''; } if ( current_user_can( 'unfiltered_html' ) ) { return wp_check_invalid_utf8( $trimmed ); } else { return wp_filter_post_kses( $trimmed ); //return wp_kses( $trimmed, 'post' ); // wp_filter_post_kses() handles slashes } } function aweaver_echo_css( $css ) { if ( is_multisite() ) { // non-superadmins have some filtering on CSS - this will fix it. //$css = stripslashes( $css ); $css = str_replace( array( '<', '>' ), array( '<', '>' ), $css ); } echo $css; } // # MISC ============================================================== function aweaver_trusted_echo( $echo_this ) { // this is used to echo trusted text that usually has HTML tags in it, possibly trusted "; } function aweaver_f_content_dir() { return trailingslashit( WP_CONTENT_DIR ); } function aweaver_f_uploads_base_url() { $wpdir = wp_upload_dir(); // get the upload directory return trailingslashit( trim( $wpdir['baseurl'] ) ); } /** * Return a big string from a file in the uploads/absolute-wvr-css directory * * @param string $filename * * @since Version 4 * */ function aweaver_read_from_upload( $filename ) { global $wp_filesystem; if ( empty( $wp_filesystem ) ) { /* load if not already present */ require_once( ABSPATH . '/wp-admin/includes/file.php' ); // ( Not a template file ) WP_Filesystem(); } $upload_dir = wp_upload_dir(); // Grab uploads folder array $dir = trailingslashit( $upload_dir['basedir'] ) . 'absolute-wvr-css' . DIRECTORY_SEPARATOR; // Set storage directory path if ( ! file_exists( $dir . $filename ) ) { return ''; } WP_Filesystem(); // Initial WP file system $contents = $wp_filesystem->get_contents( $dir . $filename ); // Store in the file. if ( is_string( $contents ) ) { return $contents; } return ''; } // # OTHER UTILS ============================================================== function aweaver_debug_comment( $msg ) { echo "\n\n"; } function aweaver_get_css_filename() { $updir = wp_upload_dir(); return trailingslashit( $updir['basedir'] ) . 'absolute-wvr-css/' . ABSOLUTE_WVR_GENERATED_STYLE_FILE; } function aweaver_get_css_url() { $updir = wp_upload_dir(); // make relative for https: - doesn't work right... $path = trailingslashit( $updir['baseurl'] ) . 'absolute-wvr-css/' . ABSOLUTE_WVR_GENERATED_STYLE_FILE; if ( is_ssl() ) { $path = str_replace( 'http:', 'https:', $path ); } return $path; } function aweaver_get_footer( $who ) { get_footer( $who ); } //-- function aweaver_generate_id() { if ( ! isset( $GLOBALS['wvrx_gen_id'] ) ) { $GLOBALS['wvrx_gen_id'] = 1; } else { $GLOBALS['wvrx_gen_id'] ++; } return $GLOBALS['wvrx_gen_id']; } //-- function aweaver_clear_both( $class = '' ) { if ( $class ) { echo '
'; } else { echo '
'; } } function aweaver_relative_url( $subpath ) { // generate a relative URL from the site's root return parse_url( trailingslashit( get_template_directory_uri() ) . $subpath, PHP_URL_PATH ); } function aweaver_filter_css( $css ) { // filter user added CSS for root relative file paths if ( strpos( $css, '%template_directory%' ) !== false ) { $css = str_replace( '%template_directory%', parse_url( trailingslashit( get_template_directory_uri() ), PHP_URL_PATH ), $css ); } if ( strpos( $css, '%stylesheet_directory%' ) !== false ) { $css = str_replace( '%stylesheet_directory%', parse_url( trailingslashit( get_stylesheet_directory_uri() ), PHP_URL_PATH ), $css ); } if ( strpos( $css, '%addon_directory%' ) !== false ) { $css = str_replace( '%addon_directory%', parse_url( trailingslashit( aweaver_f_uploads_base_url() ) . 'absolute-wvr-css/addon-subthemes/', PHP_URL_PATH ), $css ); } return $css; } add_filter( 'aweaver_css', 'aweaver_filter_css' ); // =============================== transient options ============================= if ( ! function_exists( 'aweaver_t_get' ) ) { // interface to [show_posts] function aweaver_t_get( $opt ) { return isset( $GLOBALS['aspen_temp_opts'][ $opt ] ) ? $GLOBALS['aspen_temp_opts'][ $opt ] : ''; } } function aweaver_check_editor_style() { // see if we need an update... if ( ! ( current_user_can( 'edit_theme_options' ) && current_user_can( 'activate_plugins' ) ) || is_customize_preview() ) { return; } $updir = wp_upload_dir(); $dir = trailingslashit( $updir['basedir'] ) . 'absolute-wvr-css/editor-style-awvr.css'; if ( ! aweaver_f_exists( $dir ) || aweaver_getopt( 'settings_version' ) != ABSOLUTE_WVR_SETTINGS_VERSION ) { // save latest version ) { if ( aweaver_getopt( 'settings_version' ) != ABSOLUTE_WVR_SETTINGS_VERSION ) { aweaver_setopt( 'settings_version', ABSOLUTE_WVR_SETTINGS_VERSION ); // save latest version } aweaver_save_opts( 'customizer', true ); // using customizer helps force for all situations } } ?>