'auhfc_settings[head]', 'value' => $auhfc_settings['head'], 'description' => __( 'Code to enqueue in HEAD section', 'head-footer-code' ), 'field_class' => 'widefat code', 'rows' => 7, ) ); add_settings_field( 'auhfc_footer_code', __( 'FOOTER Code', 'head-footer-code' ), 'auhfc_textarea_field_render', 'head_footer_code', 'head_footer_code_sitewide_settings', array( 'field' => 'auhfc_settings[footer]', 'value' => $auhfc_settings['footer'], 'description' => esc_html__( 'Code to enqueue in footer section (before the )', 'head-footer-code' ), 'field_class' => 'widefat code', 'rows' => 7, ) ); add_settings_field( 'auhfc_priority', __( 'Priority', 'head-footer-code' ), 'auhfc_number_field_render', 'head_footer_code', 'head_footer_code_sitewide_settings', array( 'field' => 'auhfc_settings[priority]', 'value' => $auhfc_settings['priority'], 'description' => esc_html__( 'Priority of inserted head and footer code. Default is 10. Larger number inject code closer to and .', 'head-footer-code' ), 'class' => 'num', 'min' => 1, 'max' => 1000, 'step' => 1, ) ); /** * Settings Sections are the groups of settings you see on WordPress settings pages * with a shared heading. In your plugin you can add new sections to existing * settings pages rather than creating a whole new page. This makes your plugin * simpler to maintain and creates less new pages for users to learn. * You just tell them to change your setting on the relevant existing page. */ add_settings_section( 'head_footer_code_article_settings', esc_attr__( 'Article specific Head and Footer Code', 'head-footer-code' ), 'auhfc_article_settings_section_description', 'head_footer_code' ); // Prepare clean list of post types w/o attachment $clean_post_types = get_post_types( array( 'public' => true ) ); unset( $clean_post_types['attachment'] ); add_settings_field( 'auhfc_post_types', __( 'Post types', 'head-footer-code' ), 'auhfc_checkbox_group_field_render', 'head_footer_code', 'head_footer_code_article_settings', array( 'field' => 'auhfc_settings[post_types]', 'items' => $clean_post_types, 'value' => $auhfc_settings['post_types'], 'description' => esc_html__( 'Select which post types will have Article specific section. Default is post and page. Please note, even if you have Head/Footer Code set per article and then you disable that post type, article specific code will not be printed but only site-wide code.', 'head-footer-code' ), 'class' => 'checkbox', ) ); } // END function auhfc_settings_init( ) /** * This function provides textarea for settings fields */ function auhfc_textarea_field_render( $args ) { extract( $args ); if ( empty( $rows ) ) { $rows = 7; } printf( '

%5$s

', $field, $rows, $field_class, $value, $description ); } // END function auhfc_textarea_field_render( $args ) /** * This function provides number input for settings fields */ function auhfc_number_field_render( $args ) { extract( $args ); printf( '

%7$s

', $field, // name/id $value, // value $class, // class $min, // min $max, // max $step, // step $description // description ); } // END function auhfc_number_field_render($args) /** * This function provides checkbox group for settings fields */ function auhfc_checkbox_group_field_render( $args ) { extract( $args ); // Checkbox items. $out = '
'; foreach ( $items as $key => $label ) { $checked = ''; if ( ! empty( $value ) ) { $checked = ( in_array( $key, $value ) ) ? 'checked="checked"' : ''; } $out .= sprintf( '
', $field, $key, $class, $checked, $label ); } $out .= '
'; $out .= sprintf( '

%s

', $description ); echo $out; } // eom settings_field_checkbox() function auhfc_sitewide_settings_section_description( ) { ?>

Define site-wide code and behavior. You can Add custom content like JavaScript, CSS, HTML meta and link tags, Google Analytics, site verification, etc.

Define article specific behavior.

Settings'; array_unshift( $links, $settings_link ); return $links; } // END public static function auhfc_plugin_settings_link( $links ) /** * Add link to official plugin pages * @param array $links Array of existing plugin row links. * @param string $file Path of current plugin file. * @return array Array of updated plugin row links */ function auhfc_add_plugin_meta_links( $links, $file ) { if ( 'head-footer-code/head-footer-code.php' === $file ) { return array_merge( $links, array( sprintf( '%s', __( 'Support' ) ), sprintf( '%s', __( 'Donate' ) ), ) ); } return $links; } // END function auhfc_add_plugin_meta_links( $links, $file )