* @package AnsPress * @subpackage Admin Pages */ // If this file is called directly, abort. if ( ! defined( 'WPINC' ) ) { die; } // Check if user have proper rights. if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_attr__( 'Trying to cheat, huh!', 'anspress-question-answer' ) ); } /** * Action triggered before outputting AnsPress options page. * * @since 4.1.0 */ do_action( 'ap_before_options_page' ); $all_options = array( 'general' => array( 'label' => __( 'General', 'anspress-question-answer' ), 'groups' => array( 'pages' => array( 'label' => __( 'Pages', 'anspress-question-answer' ), ), 'permalinks' => array( 'label' => __( 'Permalinks', 'anspress-question-answer' ), ), 'layout' => array( 'label' => __( 'Layout', 'anspress-question-answer' ), ), ), ), 'postscomments' => array( 'label' => __( 'Posts & Comments', 'anspress-question-answer' ), ), 'uac' => array( 'label' => __( 'User Access Control', 'anspress-question-answer' ), 'groups' => array( 'reading' => array( 'label' => __( 'Reading Permissions', 'anspress-question-answer' ), ), 'posting' => array( 'label' => __( 'Posting Permissions', 'anspress-question-answer' ), ), 'other' => array( 'label' => __( 'Other Permissions', 'anspress-question-answer' ), ), 'roles' => array( 'label' => __( 'Role Editor', 'anspress-question-answer' ), 'template' => 'roles.php', ), ), ), 'tools' => array( 'label' => __( 'Tools', 'anspress-question-answer' ), 'groups' => array( 're-count' => array( 'label' => __( 'Re-count', 'anspress-question-answer' ), 'template' => 'recount.php', ), 'uninstall' => array( 'label' => __( 'Uninstall', 'anspress-question-answer' ), 'template' => 'uninstall.php', ), ) ), ); $all_options = apply_filters( 'ap_all_options', $all_options ); /** * Action used to register AnsPress options. * * @since 4.1.0 * @since Fixed: rewrite rules not getting flushed on changing permalinks. */ do_action( 'ap_register_options' ); $form_name = ap_sanitize_unslash( 'ap_form_name', 'r' ); $updated = false; // Process submit form. if ( ! empty( $form_name ) && anspress()->get_form( $form_name )->is_submitted() ) { $form = anspress()->get_form( $form_name ); if ( ! $form->have_errors() ) { $values = $form->get_values(); $options = get_option( 'anspress_opt', [] ); foreach ( $values as $key => $opt ) { $options[ $key ] = $opt['value']; } update_option( 'anspress_opt', $options ); wp_cache_delete( 'anspress_opt', 'ap' ); wp_cache_delete( 'anspress_opt', 'ap' ); // Flush rewrite rules. if ( 'form_options_general_pages' === $form_name || 'form_options_general_permalinks' === $form_name ) { $main_pages = array_keys( ap_main_pages() ); foreach ( $main_pages as $slug ) { if ( isset( $values[ $slug ] ) ) { $_post = get_post( $values[ $slug ]['value'] ); ap_opt( $slug . '_id', $_post->post_name ); } } ap_opt( 'ap_flush', 'true' ); flush_rewrite_rules(); } $updated = true; } } ?>